Overview
Control whether to automatically add the featured image to JSON-LD output.
Description
By default, ACF automatically includes the post’s featured image in the JSON-LD output as an ImageObject. This filter allows you to disable this behavior for specific posts or post types.
Changelog
- Added in version 6.8.0
Parameters
apply_filters( 'acf/schema/auto_add_image', $add_image, $post, $post_type );
$add_image(bool) Whether to add the featured image. Default:true$post(WP_Post) The post object$post_type(string) The post type name
Return
(bool) Whether to add the featured image to JSON-LD output.
Example
This example disables auto image for products (using a custom ACF image field instead).
/**
* Disable auto image for products.
*
* @param bool $add_image Whether to add featured image.
* @param WP_Post $post The post object.
* @param string $post_type The post type.
* @return bool Whether to add featured image.
*/
function my_acf_schema_disable_product_image( $add_image, $post, $post_type ) {
if ( $post_type === 'product' ) {
return false;
}
return $add_image;
}
add_filter( 'acf/schema/auto_add_image', 'my_acf_schema_disable_product_image', 10, 3 );
This example only adds images for posts with a featured image set.
/**
* Only add image if featured image exists.
*
* @param bool $add_image Whether to add featured image.
* @param WP_Post $post The post object.
* @param string $post_type The post type.
* @return bool Whether to add featured image.
*/
function my_acf_schema_require_featured_image( $add_image, $post, $post_type ) {
if ( ! has_post_thumbnail( $post->ID ) ) {
return false;
}
return $add_image;
}
add_filter( 'acf/schema/auto_add_image', 'my_acf_schema_require_featured_image', 10, 3 );
Supercharge Your Website With Premium Features Using ACF PRO
Speed up your workflow and unlock features to better develop websites using ACF Blocks and Options Pages, with the Flexible Content, Repeater, Clone, Gallery Fields & More.
Related
- Filters: acf/schema/auto_add_author
- Filters: acf/schema/block_jsonld_enabled
- Filters: acf/schema/data
- Filters: acf/schema/disable_output
- Filters: acf/schema/post_field_objects