Javascript

How to Add Schema.org JSON-LD to WordPress (2026 Guide)

By Ken Key Aug 25, 2026 4 min read Updated Oct 16, 2026

How to Add Schema.org JSON-LD to WordPress (2026 Guide)
The short answer

Add JSON-LD by hooking a script tag into wphead in your child theme's functions.php, or by pasting it into a header plugin or an HTML block. Build the JSON from your post data, validate it in Google's Rich Results Test, and never let two plugins output schema for the same page.

Part of the complete SEO guide.

On this page

Most WordPress sites I audit are either missing structured data entirely or have three plugins fighting over the same <head> tag. Adding schema.org JSON-LD yourself is not hard. The trick is putting it in the right place and keeping it valid as your content changes.

What JSON-LD actually is (and why it beats microdata)

JSON-LD is a block of JSON that describes your page to search engines. It sits inside a <script type="application/ld+json"> tag, usually in the head or the body, and it does not touch your visible HTML. Google has recommended JSON-LD over microdata and RDFa since 2017, and in 2026 it is effectively the only format you should bother with.

A minimal Organization block looks like this:

<script type="application/ld+json">
{
 "@context": "https://schema.org",
 "@type": "Organization",
 "name": "Your Business Name",
 "url": "https://example.com",
 "logo": "https://example.com/logo.png",
 "contactPoint": {
 "@type": "ContactPoint",
 "telephone": "+1-631-555-0100",
 "contactType": "customer service"
 }
}
</script>

That is it. No attributes, no visible markup, no dependency on your theme’s HTML structure.

Option 1: Hardcode it in functions.php

If you control your theme (or a child theme), this is the cleanest approach. You output the JSON yourself and you know exactly what is on the page.

add_action( 'wp_head', function () {
 if ( ! is_singular( 'post' ) ) {
 return;
 }

 $post_id = get_the_ID();

 $data = [
 '@context' => 'https://schema.org',
 '@type' => 'BlogPosting',
 'headline' => get_the_title( $post_id ),
 'datePublished' => get_the_date( 'c', $post_id ),
 'dateModified' => get_the_modified_date( 'c', $post_id ),
 'author' => [
 '@type' => 'Person',
 'name' => get_the_author_meta( 'display_name', get_post_field( 'post_author', $post_id ) ),
 'url' => get_author_posts_url( get_post_field( 'post_author', $post_id ) ),
 ],
 'mainEntityOfPage' => [
 '@type' => 'WebPage',
 '@id' => get_permalink( $post_id ),
 ],
 ];

 $image = get_the_post_thumbnail_url( $post_id, 'full' );
 if ( $image ) {
 $data['image'] = [ $image ];
 }

 echo '<script type="application/ld+json">'
 . wp_json_encode( $data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE )
 . '</script>';
} );

Two things matter here. First, get_the_modified_date( 'c' ) gives you ISO 8601, which is what schema wants. Second, wp_json_encode() handles escaping for you. Do not hand-build JSON strings with concatenation.

Adding FAQ schema

FAQ rich results got a lot narrower in 2023 and Google now mostly shows them for authoritative health and government sites. That said, marking up a real FAQ still helps with entity understanding, and it costs you nothing.

$faq = [
 '@context' => 'https://schema.org',
 '@type' => 'FAQPage',
 'mainEntity' => [
 [
 '@type' => 'Question',
 'name' => 'How much does a custom WordPress theme cost?',
 'acceptedAnswer' => [
 '@type' => 'Answer',
 'text' => 'It depends on scope, but most custom builds start in the low five figures.',
 ],
 ],
 ],
];

Only mark up questions that are actually visible on the page. Google penalizes hidden FAQ markup.

Option 2: Use a plugin (and know its limits)

Yoast and Rank Math both ship solid schema graphs out of the box. If you just need Article, Breadcrumb, and Organization, either will do, and you should not be writing custom code for it. Where plugins fall short is anything that has to reflect your real data: course catalogs, service areas, product variants, local business hours that change by season.

If you are already running a plugin, check for duplicate output before adding your own. View source and search for application/ld+json. If you see two Article blocks, you have a conflict, and Google will usually pick one at random.

The mistakes that actually break rich results

  • Wrong @type. Article is fine, but BlogPosting and NewsArticle are more specific and Google treats them differently.
  • Fake or missing images. The image field needs to resolve to a real, crawlable URL. Relative paths fail.
  • Dates in the wrong format. “January 5, 2026” is not valid. Use 2026-01-05T09:00:00-05:00.
  • Marking up content that is not on the page. Ratings, prices, FAQs. This is the fastest way to get a manual action.
  • Blocking the JSON-LD with a caching plugin. Some minifiers strip <script> tags they do not recognize. Test with caching on.

How to verify it in 2026

Use the Schema Markup Validator at validator.schema.org for syntax, and Google’s Rich Results Test for eligibility. They are different tools and you want both. The Rich Results Test tells you what Google will actually do with your markup. The validator tells you whether your JSON is structurally sound.

For high-volume sites, the URL Inspection tool in Search Console shows detected structured data per URL after Google recrawls. That is the ground truth.

When to stop hand-rolling it

If your schema needs to pull from custom post types, taxonomies, or an external API, hand-coding gets messy fast. At that point the JSON-LD output should be part of the same system that renders your pages. That is the kind of thing I build for clients as part of custom web development, and it is usually paired with the on-page work I do in Long Island SEO engagements. Structured data without matching content does not rank. Content without structured data leaves free visibility on the table.

FAQ

Does JSON-LD still help rankings in 2026?

It does not directly boost rankings, but it drives rich results, which raise click-through rate. It also helps Google understand entities, which matters more now that AI answers pull from structured sources.

Will Yoast and my custom code conflict?

Yes, if both output the same type on the same URL. Either disable the plugin’s schema for that post type or remove your custom block. Never run both.

Where should the script tag go, head or body?

Google accepts either. Head is conventional and easier to audit. If you inject it in the body, keep it near the top so it is not lost when a page is truncated.

Have a project like this?

I do custom web development for Long Island businesses. If you need this done right, let’s talk.