Last active
December 28, 2020 18:04
-
-
Save djrmom/4e25495948d52ad9fc93c975c04071f3 to your computer and use it in GitHub Desktop.
facetwp custom image size for ACF image field in layout builder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
** for creating custom image sizes | |
** https://developer.wordpress.org/reference/functions/add_image_size/ | |
**/ | |
add_filter( 'facetwp_builder_item_value', function( $value, $item ) { | |
if ( 'my-image' == $item['settings']['name'] && !empty( $value ) ) { // change 'my-image' to the unique name of your field | |
$image = get_field('acf_image_field'); // change 'acf_image_field' to the name of your acf field | |
if ( $image ) $value = wp_get_attachment_image( $image, 'thumbnail' ); // 'thumbnail' can be changed to other image sizes you have available | |
} | |
return $value; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment