跳转到主要内容

acf/schema/block_jsonld_enabled

Enable or disable JSON-LD output for specific blocks.

Description

This filter allows you to programmatically control whether JSON-LD output is enabled for specific ACF blocks. This runs after checking the block’s autoJsonLd setting, allowing you to override the default behavior.

Changelog

  • Added in version 6.8.0

Parameters

apply_filters( 'acf/schema/block_jsonld_enabled', $enabled, $block, $block_type );
  • $enabled (bool) Whether JSON-LD is enabled for this block (from autoJsonLd setting)
  • $block (array) The block props array containing block data
  • $block_type (array) The registered block type settings

Return

(bool) Whether to output JSON-LD for this block.

Example

This example enables JSON-LD for all recipe blocks regardless of settings.

/**
 * Force enable JSON-LD for recipe blocks.
 *
 * @param bool  $enabled    Whether JSON-LD is enabled.
 * @param array $block      The block props.
 * @param array $block_type The block type settings.
 * @return bool Whether to enable JSON-LD.
 */
function my_acf_schema_enable_recipe_blocks( $enabled, $block, $block_type ) {
    if ( $block['name'] === 'acf/recipe' ) {
        return true;
    }
    return $enabled;
}
add_filter( 'acf/schema/block_jsonld_enabled', 'my_acf_schema_enable_recipe_blocks', 10, 3 );

This example disables JSON-LD for blocks in preview mode.

/**
 * Disable JSON-LD in preview context.
 *
 * @param bool  $enabled    Whether JSON-LD is enabled.
 * @param array $block      The block props.
 * @param array $block_type The block type settings.
 * @return bool Whether to enable JSON-LD.
 */
function my_acf_schema_disable_preview_jsonld( $enabled, $block, $block_type ) {
    if ( isset( $block['data']['preview'] ) && $block['data']['preview'] ) {
        return false;
    }
    return $enabled;
}
add_filter( 'acf/schema/block_jsonld_enabled', 'my_acf_schema_disable_preview_jsonld', 10, 3 );