Skip to content
JIX edited this page Jul 14, 2020 · 1 revision

Purpose

The Image field builds on top of the File field and only allows the selection of images.

image-field

Settings

The Image field has the same settings as the File field. The only exception is the output format, described below.

Output type

The image field supports the following output types for when it is used in combination with a the_value function:

  • image: Generates a complete image tag (default).
  • link: Generates a link to the image.
  • url: Generates the URL of the image.
  • id: Returns the ID of the image.

In PHP you can use the set_output_type method in combination with one of the slugs above.

Output Size

If you have set the "Output Type" to image, you can adjust which image size should be used when the image is generated.

In PHP use the set_output_size method along with the slug of the image size, added by add_image_size.

Field::create( 'image', 'header_image' )->set_output_size( 'header' );

Usage

When you use an image field in combination with a get_value function, the ID of the selected image will be returned, if any.

the_value functions will display the type of value, selected for "Output Type".

<!-- Displays a full img tag when output type is set to `image` -->
<?php the_value( 'header_image' ) ?>
Clone this wiki locally