跳转到主要内容

acf/schema/data

Filter the final JSON-LD data before output.

Description

This filter allows you to modify the complete JSON-LD structured data array before it is rendered to the page. Use this to add custom properties, modify existing values, or conditionally alter the output based on the post or block context.

This filter runs for both post-based and block-based JSON-LD output.

Changelog

  • Added in version 6.8.0

Parameters

apply_filters( 'acf/schema/data', $data, $object, $type );
  • $data (array) The JSON-LD data array containing all mapped properties
  • $object (WP_Post|array) The post object (for posts) or block array (for blocks)
  • $type (string|array) The post type name or block type settings

Return

(array) The modified JSON-LD data array.

Example

This example adds a publisher organization to all Article schema types.

/**
 * Add publisher to Article JSON-LD output.
 *
 * @param array           $data   The JSON-LD data array.
 * @param WP_Post|array   $object The post or block object.
 * @param string|array    $type   The post type or block type.
 * @return array Modified JSON-LD data.
 */
function my_acf_schema_add_publisher( $data, $object, $type ) {
    // Only add publisher to Articles
    if ( isset( $data['@type'] ) && $data['@type'] === 'Article' ) {
        $data['publisher'] = array(
            '@type' => 'Organization',
            'name'  => get_bloginfo( 'name' ),
            'url'   => home_url(),
            'logo'  => array(
                '@type' => 'ImageObject',
                'url'   => get_site_icon_url(),
            ),
        );
    }

    return $data;
}
add_filter( 'acf/schema/data', 'my_acf_schema_add_publisher', 10, 3 );