acf/schema/auto_add_author
目录
Control whether to automatically add author information to JSON-LD output.
Description
By default, ACF automatically includes the post author in the JSON-LD output as a Person object with name and URL. 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_author', $add_author, $post, $post_type );
Return
(bool) Whether to add author information to JSON-LD output.
Example
This example disables auto author for pages.
/**
* Disable auto author for pages.
*
* @param bool $add_author Whether to add author.
* @param WP_Post $post The post object.
* @param string $post_type The post type.
* @return bool Whether to add author.
*/
function my_acf_schema_disable_page_author( $add_author, $post, $post_type ) {
if ( $post_type === 'page' ) {
return false;
}
return $add_author;
}
add_filter( 'acf/schema/auto_add_author', 'my_acf_schema_disable_page_author', 10, 3 );
This example disables auto author when using a custom author ACF field.
/**
* Disable auto author when custom author field exists.
*
* @param bool $add_author Whether to add author.
* @param WP_Post $post The post object.
* @param string $post_type The post type.
* @return bool Whether to add author.
*/
function my_acf_schema_custom_author_field( $add_author, $post, $post_type ) {
// If we have a custom author field mapped, don't add the auto author
$custom_author = get_field( 'article_author', $post->ID );
if ( $custom_author ) {
return false;
}
return $add_author;
}
add_filter( 'acf/schema/auto_add_author', 'my_acf_schema_custom_author_field', 10, 3 );