wprichsnippets
Guide · WordPress · How-tosCERT No. WP R003

Google Rich Snippets in WordPress: A Block Editor Walkthrough

Schema type
Review Rating Book
Checked against
Google Search Central, Search Console Help and WordPress.org documentation, read November 2026
Author
The wprichsnippets.com editors
Published
Updated
Direct answerField 01

To add Google rich snippets in WordPress, write the review, recipe or product details visibly in the block editor, keep the values the markup needs in custom fields or a plugin's settings, print one JSON-LD block in the page head, then test the live URL in the Rich Results Test before asking Google to recrawl.

55 wordsUpdated November 19, 2026
FeatureFig. 01
A stack of editor blocks feeding a single sealed data card that slots into a search result frame
The post shows the facts; one JSON-LD block repeats them for machines.

01How do Google rich snippets work in WordPress?

Google rich snippets in WordPress work the same way they do on any site: the page carries structured data, Google reads it, and the page becomes eligible for an enhanced result such as review stars. WordPress only changes where the markup comes from. It might be your theme, an SEO plugin, a block, or a few lines of your own code.

Google's introduction to structured data anticipates this. It notes that on a CMS such as WordPress you may not edit HTML directly, and that a settings page or plugin may let you specify structured data instead. It also sets the rule every route has to follow: do not mark up information that is not visible to the user.

This walkthrough uses a book review as the example, because review snippets are a feature Google still supports for books. The same steps work for a recipe, an event or a product. If you want to know whether your content type still has a rich result at all, check the six eligibility steps first.

02Which route should you use?

Three ways to get JSON-LD onto a WordPress page
RouteWho controls the outputBest forWatch out for
SEO or schema pluginThe plugin's templatesSites that already run one and want site-wide typesDuplicates if the theme or a second plugin also prints markup
Custom HTML block with a scriptThe person editing the postA one-off pageNeeds the unfiltered_html capability; easy to break by hand
Custom fields plus a small pluginYour codeRepeated content, such as a review on every postYou maintain the code

The rest of this guide follows the third route, because it keeps the visible content in blocks, keeps the values in fields an editor can see, and keeps the JSON in one place where it cannot be mistyped. A Custom HTML block works for a single page, but WordPress's roles and capabilities documentation notes that only users with unfiltered_html may post script code, and on multisite that is only Super Admins.

03Step by step: from the block editor to a tested result

  1. Write the review visibly. In the block editor, add the book's title in a heading, the verdict in a paragraph and the score as text readers can see, for example "Rating: 4 out of 5". The markup will repeat these facts, so they must be on the page.
  2. Show the Custom Fields panel. WordPress hides it until it is used. WordPress.org's custom fields documentation gives the path: Options (the three-dot menu), Preferences, General, then turn on Custom fields under Advanced and reload.
  3. Add two fields. Create review_item_name with the book title and review_rating with the number. Avoid a leading underscore, because WordPress treats those keys as hidden.
  4. Install the small plugin below as a must-use plugin, so it prints JSON-LD in the head of any post that has both fields.
  5. View the page source and search for application/ld+json. Count the blocks. If your SEO plugin also prints a Review, remove one source.
  6. Run the Rich Results Test on the live URL, then on a draft by pasting code, and fix every critical issue.
  7. Ask Google to recrawl with URL Inspection in Search Console, then watch the Review snippets report.

04The code: print JSON-LD with wp_head

The wp_head hook fires inside the theme's <head> section, and WordPress's reference calls it one of the most essential theme hooks, so almost every theme supports it. The snippet below hooks into it, reads the two fields, and prints one Review object. Save it as a file in wp-content/mu-plugins/.

Example 1 · PHP: Review markup from two custom fieldsPHPDisplay only
1<?php2/**3 * Plugin Name: Example review JSON-LD from custom fields4 * Description: Prints Review markup on posts that have review_item_name and review_rating.5 */6add_action( 'wp_head', function () {7	if ( ! is_singular( 'post' ) ) {18		return;9	}10	$post_id = get_queried_object_id();11	$item    = get_post_meta( $post_id, 'review_item_name', true );12	$rating  = get_post_meta( $post_id, 'review_rating', true );13	if ( '' === $item || '' === $rating ) {214		return; // No review on this post, so print nothing.15	}16	$data = array(17		'@context'      => 'https://schema.org',18		'@type'         => 'Review',19		'itemReviewed'  => array( '@type' => 'Book', 'name' => $item ),20		'reviewRating'  => array(21			'@type'       => 'Rating',22			'ratingValue' => (float) $rating,23			'bestRating'  => 5,24			'worstRating' => 1,25		),26		'author'        => array(27			'@type' => 'Person',28			'name'  => get_the_author_meta( 'display_name', get_post_field( 'post_author', $post_id ) ),29		),30		'datePublished' => get_the_date( 'c', $post_id ),31	);32	echo '<script type="application/ld+json">' . wp_json_encode( $data ) . '</script>' . "\n";333} );
  1. 1Line 7Only single posts; archives and pages are skipped
  2. 2Line 13No fields, no markup: nothing is printed for posts that are not reviews
  3. 3Line 32wp_json_encode escapes quotes and slashes so the JSON stays valid

wp_json_encode does the escaping, which is why the code never builds JSON by joining strings. A title with a quotation mark in it would otherwise break the block and send it to the unparsable report. Our guide to adding schema without a plugin covers mu-plugins, escaping and per-post data in more depth.

This is what the snippet prints for a post with the fields filled in, with example values:

Example 2 · the JSON-LD the snippet printsJSON-LDDisplay only
1{2  "@context": "https://schema.org",3  "@type": "Review",4  "itemReviewed": {5    "@type": "Book",6    "name": "Example Book Title"7  },8  "reviewRating": {9    "@type": "Rating",10    "ratingValue": 4,111    "bestRating": 5,12    "worstRating": 113  },14  "author": {15    "@type": "Person",16    "name": "Example Author"17  },18  "datePublished": "2026-11-19T09:00:00+00:00"19}
  1. 1Line 10ratingValue matches the score shown in the post

05What if two sources print the same item?

Duplicates are the most common WordPress structured data problem, because themes, SEO plugins, review blocks and store plugins each print markup without knowing about the others. Unless the blocks are linked with @id, Google reads each one as its own item, so the report counts both and duplicate fields can follow.

Deciding which source keeps the markup
You findKeepTurn off
Theme and SEO plugin both print ArticleThe SEO plugin, which usually builds a linked graphThe theme's markup, through its settings or a child theme
A review block and your custom code both print ReviewWhichever reads the same values readers seeThe other one
Two SEO plugins activeOne pluginThe second plugin entirely

Decide once and write the decision down in the site's notes. When a plugin update adds a new type, the same question comes back, and a recorded choice saves a second audit.

06How do you test rich snippets in WordPress?

Google's Rich Results Test help page describes two modes. URL mode fetches the page as Google would, so every resource must be reachable by an anonymous visitor; a staging site behind a password cannot be tested that way. Code mode accepts a pasted snippet, which is the quickest way to test a draft.

The same page warns about one trap. The test ignores comments inside JSON-LD, but comments are not part of the JSON-LD standard and can cause errors in real use, so remove them before publishing. If the report later shows a message you do not recognize, the structured data error map lists the common ones with fixes.

07What is schema in WordPress, and what should you check after launch?

Schema in WordPress usually means schema.org structured data printed by the theme, a plugin or custom code. Most WordPress sites already print some, often a WebSite, Organization and Article graph from an SEO plugin, so the real job is knowing what is there before adding more.

  • One Review per review: two sources printing the same item produce duplicate fields.
  • Visible score equals ratingValue: change one, change both.
  • The page is indexable: no noindex from a plugin setting and no robots.txt block.
  • Dates are honest: datePublished comes from the post, not the time of the request.

For the wider question of what this markup is for, see how does structured data work on a WordPress site? on the home page, and the WordPress section for every guide on adding, testing and fixing it.

08Questions

Q1Does WordPress add rich snippets by default?

WordPress core does not print schema.org structured data for posts on its own. Many themes and SEO plugins do, and WooCommerce prints Product markup for products. Check a page's source for application/ld+json to see what your site already outputs before you add anything.

Q2Can I add JSON-LD in a Custom HTML block?

Yes, if your account has the unfiltered_html capability, which WordPress gives to Administrators and Editors on a single site and only to Super Admins on multisite. It suits one page. For markup repeated across many posts, a small plugin reading custom fields is easier to keep correct.

Q3Why does the Rich Results Test not see my markup?

The test fetches the page as Google, so it cannot see markup behind a login, on a password-protected staging site, or on a URL blocked by robots.txt. Test drafts in code mode instead, and check that a caching plugin is serving the updated page.

Q4Will review stars show for every review post?

No. Valid markup makes a post eligible, and Google decides whether to show stars for each search. Stars also never show for a business reviewing itself, and the score in the markup must match what readers can see on the page.

09Sources

  1. wp_head hookWordPress Developer Resources
  2. Roles and capabilitiesWordPress.org Documentation
  3. Rich Results TestSearch Console Help