acf/schema/enabled_post_types
Filter the list of post types that have JSON-LD output enabled.
Description
This filter allows you to programmatically enable JSON-LD output for post types without using the admin UI. This is useful for enabling JSON-LD on post types registered by other plugins or for dynamically controlling which post types output structured data.
Changelog
- Added in version 6.8.0
Parameters
apply_filters( 'acf/schema/enabled_post_types', $post_types );
$post_types(array) Array of post type names that have JSON-LD enabled via the admin UI
Return
(array) The modified array of post type names.
Example
This example enables JSON-LD output for WooCommerce products.
/**
* Enable JSON-LD for WooCommerce products.
*
* @param array $post_types Array of enabled post type names.
* @return array Modified array of post type names.
*/
function my_acf_schema_enable_products( $post_types ) {
$post_types[] = 'product';
return $post_types;
}
add_filter( 'acf/schema/enabled_post_types', 'my_acf_schema_enable_products' );
This example conditionally enables JSON-LD based on environment.
/**
* Only enable JSON-LD on production.
*
* @param array $post_types Array of enabled post type names.
* @return array Modified array of post type names.
*/
function my_acf_schema_production_only( $post_types ) {
if ( wp_get_environment_type() !== 'production' ) {
return array(); // Disable all JSON-LD output
}
return $post_types;
}
add_filter( 'acf/schema/enabled_post_types', 'my_acf_schema_production_only' );
这篇文档对你有帮助吗?
谢谢你的反馈!