Overview
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' );
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/data
- Filters: acf/schema/post_field_objects/post_type={post_type}
- Filters: acf/schema/block_jsonld_enabled
- Filters: acf/schema/disable_output
- Filters: acf/schema/post_field_objects