Description
This gform_image_sizes filter allows you to customize the image sizes that are registered for the Image Choice fields. You can modify the width, height, and crop settings for the small, medium, and large image choice sizes registered by default.
Usage
add_filter( 'gform_image_sizes', 'your_function_name', 10, 1 );
Parameters
Parameter | Type | Description |
---|---|---|
$image_sizes | array | An array of image sizes with their respective attributes. Each size contains width, height, and crop settings. |
Default Sizes
array(
'image-choice-sm' => array(
'width' => 300,
'height' => 300,
'crop' => true
),
'image-choice-md' => array(
'width' => 400,
'height' => 400,
'crop' => true
),
'image-choice-lg' => array(
'width' => 600,
'height' => 600,
'crop' => true
),
)
Examples
Modify image sizes for all forms.
add_filter( 'gform_image_sizes', 'customize_gf_image_sizes', 10, 1 );
function customize_gf_image_sizes( $image_sizes ) {
$image_sizes['image-choice-sm']['width'] = 250;
$image_sizes['image-choice-sm']['height'] = 250;
$image_sizes['image-choice-md']['width'] = 500;
$image_sizes['image-choice-md']['height'] = 500;
$image_sizes['image-choice-lg']['width'] = 800;
$image_sizes['image-choice-lg']['height'] = 800;
return $image_sizes;
}
Placement
This code can be used in the functions.php file of the active theme, a custom functions plugin, a custom add-on, or with a code snippets plugin.
See also the PHP section in this article: Where Do I Put This Code?
Source Code
This filter is located in GFForms::get_image_sizes() in gravityforms.php
Since
This filter was added in Gravity Forms 2.9.