Add JSON-LD Structured Data to WordPress

What is JSON-LD?

JSON-LD is a way of representing structured data so that web pages become more understandable to machines. Its purpose is to make page content more semantic and easier for search engines and other systems to interpret.

Search engines can use JSON-LD to generate rich results in search listings. A common example is recipe search results that display ingredients and steps directly in the results page. That is possible because the structured data helps the search engine understand the content more precisely.

Add JSON-LD structured data to WordPress with code

The following example is a piece of code once used on this site to output structured data. If you place code like this in your theme’s functions.php, the structured data can be printed on every page of the site.

add_action('wp_head', function ()
{
    // Open script
    $html = '<script type="application/ld+json">';

    $html .= '{';
    $html .= '"@context": "http://schema.org",';
    $html .= '"@type": "WebSite",';
    $html .= '"name": "WordPress Zhiku",';
    $html .= '"alternateName": "WP Zhiku"';
    $html .= '}';

    $html .= '</script>';

    echo $html;
});
  • "@context": "http://schema.org" tells parsers that the data follows a schema.org vocabulary.
  • "@type": "WebSite" indicates that the structured data describes a website.
  • "name": "WordPress Zhiku" defines the primary site name.
  • "alternateName": "WP Zhiku" provides an alternate site name.

Because this is inside a script block, normal users do not see it directly, but search engines can read it and understand more about the site. For more data types and usage patterns, see the official schema.org documentation.

Add JSON-LD structured data to WordPress with plugins

Adding JSON-LD by hand can be tedious and error-prone, so site owners who are less comfortable with code may prefer to use a plugin. Some plugins that can add JSON-LD structured data in WordPress include:

  • Markup (JSON-LD) structured in schema.org
  • Schema
  • WP SEO Structured Data Schema

These plugins are broadly similar, so you can choose one based on your own needs. In addition, the popular Yoast SEO plugin already outputs several types of JSON-LD data by default, including site search information, site identity, logo data, social profile data, and breadcrumbs.

One important reminder: do not add JSON-LD excessively just for SEO. Only add structured data that actually matches the visible page content. Otherwise, search engines may treat it as over-optimization or misleading markup.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *