facetwp custom image featured image size in layout builder

djrmom

{{gist file=”custom-hooks.php” lang=”php”}}
<?php

/** create your own image size, you may need to use a plugin such as https://wordpress.org/plugins/regenerate-thumbnails/
** for existing images **/
add_image_size( ‘my_custom_image_size’, 300, 200, true ); // 300 pixels wide by 200 pixels tall, hard crop mode

/** filter layout builder featured image to out the custom image instead of the selected size in builder settings **/
add_filter( ‘facetwp_builder_item_value’, function( $value, $item ) {

if ( ‘featured_image’ == $item[‘source’] && !empty( $value ) ) {
$value = get_the_post_thumbnail( get_the_ID(), ‘my_custom_image_size’ );
}

return $value;
}, 10, 2 );
{{/gist}}