A WordPress media library image picker. Stores the attachment ID.
Field::image(string $key): ImageField->returnFormat(string $format): staticControls what ctrlfield_get() returns. Options:
| Format | Returns |
|---|---|
'id' (default) |
int — attachment ID |
'url' |
string — full image URL |
'array' |
array — ['id', 'url', 'width', 'height', 'alt'] |
->previewSize(string $size): staticRegistered WordPress image size shown in the editor — thumbnail, medium (default), medium_large, large, full or a theme's own size. It also sets the preview's width.
In the editor, the × on the preview removes the image; Select Image shows only while the field is empty, so a field never holds an image the theme does not read.
Always stored as an integer attachment ID.
{ "hero_image": 155 }Field::image('hero_image')
->label('Hero Image')
->returnFormat('array'),@php $hero = ctrlfield_get('hero_image') @endphp
@if($hero)
<img
src="{{ $hero['url'] }}"
alt="{{ $hero['alt'] }}"
width="{{ $hero['width'] }}"
height="{{ $hero['height'] }}"
>
@endifWith returnFormat('url'):
<img src="{{ ctrlfield_get('logo') }}" alt="Logo">