Skip to content

gfic_image_style

Description

This PHP filter can be used to programmatically set the image display style on Image Choices fields

Usage

Applies to all fields.

add_filter( 'gfic_image_style', 'set_image_choices_display_style', 10, 4 );

Applies to all fields in a specific form. In this case, form id 5.

add_filter( 'gfic_image_style_5', 'set_image_choices_display_style', 10, 4 );

Applies to specific field and form. In this case, field id 3 in form id 5.

add_filter( 'gfic_image_style_5_3', 'set_image_choices_display_style', 10, 4 );

Parameters

  • $value string
    The current display style setting. Defaults to “form_setting”.
  • $form_id integer
    The current form id.
  • $field_id integer
    The current field id.
  • $default_value string
    The plugin’s default value for this option.

Examples

This example sets the image display style to natural for all Image Choices fields:

add_filter( 'gfic_image_style', 'set_image_choices_display_style', 10, 4 );
function set_image_choices_display_style($value, $form_id, $field_id, $default_value) {
    return "natural";
}

Supported Values

Below are all the supported values for the image style setting:

  • form_setting (default)
    Will use the style defined in the form settings.
  • theme_default
    Will use style that is default for the selected Image Choices theme. Typically this will be “cover”
  • cover
    The image is sized to maintain its aspect ratio while filling the entire container for the selected Image Choices theme. The container has a fixed height across all choices. If the image’s aspect ratio does not match the aspect ratio of the container, then it will be clipped to fit.
  • contained
    The image is scaled to maintain its aspect ratio while fitting within the container for the selected Image Choices theme. The container has a fixed height across all choices. The entire image is made to fill the container, while preserving its aspect ratio, so the image will be “letterboxed” if its aspect ratio does not match the aspect ratio of the container.
  • natural
    The image is scaled to maintain its aspect ratio and fill the container for the selected Image Choices theme with no “letterboxing”. The container height automatically adjusts to match the image scaled height. If using images with varying aspect ratios in the same field, the choices will also have varying heights accordingly.

Placement

This code should be placed in the functions.php file of your active theme.

Source Code

This filter is located in the get_field_settings_value function in class-gf-image-choices.php