Schema.org JSON-LD

Structured data · rich snippets · WordPress

Select the schema type, fill in the fields and get JSON-LD for HTML or functions.php. Includes notes on conflicts with Yoast and RankMath and how to handle them.

Schema type

Adding JSON-LD to WordPress

The cleanest approach is to hook wp_head in functions.php and print a <script type="application/ld+json"> tag using json_encode(), so the schema uses real post or page data.

Static schema (quick test)

For a fast check you can paste the script into a PHP template:

<!-- e.g. header.php -->
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "WebSite",
  "name": "Site name",
  "url": "https://yoursite.com"
}
</script>

Dynamic schema from functions.php

add_action( 'wp_head', 'my_theme_schema_article' );

function my_theme_schema_article() {
    if ( ! is_single() ) return;

    $schema = [
        '@context' => 'https://schema.org',
        '@type'    => 'Article',
        'headline' => get_the_title(),
        'url'      => get_permalink(),
        'author'   => [
            '@type' => 'Person',
            'name'  => get_the_author(),
        ],
        'datePublished' => get_the_date( 'c' ),
        'dateModified'  => get_the_modified_date( 'c' ),
    ];

    if ( has_post_thumbnail() ) {
        $schema['image'] = get_the_post_thumbnail_url( null, 'large' );
    }

    echo '<script type="application/ld+json">'
       . json_encode( $schema, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT )
       . '</script>';
}

Schema with ACF Pro

// LocalBusiness example with ACF fields
$schema = [
    '@context'  => 'https://schema.org',
    '@type'     => 'LocalBusiness',
    'name'      => get_field( 'company_name' ),
    'telephone' => get_field( 'phone' ),
    'address'   => [
        '@type'           => 'PostalAddress',
        'streetAddress'   => get_field( 'street' ),
        'addressLocality' => get_field( 'city' ),
        'postalCode'      => get_field( 'zip' ),
        'addressCountry'  => 'GB',
    ],
];
Always validate markup with Google’s Rich Results test — requirements change per schema type.
Do not output the same schema type twice on one page. If Yoast, Rank Math, or similar plugins already emit JSON-LD, disable duplicate types before adding custom markup.

Schema.org structured data helps Google understand page content and display rich results in the SERP: star ratings, expandable FAQs, breadcrumbs and event markup increase organic visibility and CTR.

This generator supports:

  • Article: author, publication date, image, publisher
  • LocalBusiness: name, address, hours, contacts, coordinates
  • BreadcrumbList: hierarchical navigation structure
  • FAQPage: structured questions and answers for rich snippets

Produces both the <script type="application/ld+json"> tag for HTML and a PHP snippet for wp_head() with a dynamic ACF fields variant. Includes notes on conflicts with Yoast and RankMath.

Why use JSON-LD

  • Clear signals: title, dates, author, price, and FAQ are explicit for crawlers.
  • JSON-LD in the <head>: preferred format; avoid duplicating the same schema type already output by an SEO plugin.
  • Testing: after deploy, run Google’s Rich Results test and refresh fields when guidelines change.