| WordPress
How to Add Microdata for Products to WordPress Pages

Microdata makes it possible for search engines to understand important details about your site's content.

We talked about WordPress microdata in a previous blog post. However, this time we will go more specific and show you how to add Products microdata to your WordPress pages without using a plugin.

This is very useful to promote the value of the products you sell through a WordPress site. Let's start...

Microdata adds extra information to search results. When somebody is looking for your site’s products through Google, they see the ratings, price, number of reviews, etc…

Microdata on a WordPress product

Step #1. Check if your theme uses microdata

Some themes may provide microdata support, but many do not.

Google's structured data testing tool

On the left side of the screen, you can see the HTML code of your page. On the right, you can see the detected microdata.

In this case, no microdata was found on my test and that's why results are blank.

Results in Google's structured data testing tool

Step #2. Create a child theme

In order to add microdata to WordPress, you need to modify the theme files. So, we will use a child theme.The child theme allows us to keep the customizations secure in case the original theme is updated later.

If you are new to child themes, we recommend that you use the Child theme configurator plugin to easily create the child theme and copy the required files where our changes will live:

Once Child theme configurator is installed and activated, go to:

  • Tools > Child Themes > Files.
  • Select the files that render a page (commonly page.php)
  • Click Copy Selected to Child Theme

Create a child theme in Wordpress

At this point, your child theme should be activated. You can confirm this from Appearance > Themes.

Step #3. Rename the page template from your child theme

Manually rename the page.php file you just copied to your child theme. Find this file via FTP or cPanel) on /wp-content/themes/your-child-theme-folder/.

Rename the file to something unique such as page-product.php or page-custom.php - always leaving "page-" as prefix.

Create a page template in WordPress

Now, through your WordPress dashboard:

  • Go to Appearance > Editor.
  • Select page-product.php file (or whichever name you decided)


On the beginning of the file, add this code wrapped by PHP tags:

 * Template Name: Page Product

This is how it will look:

A WordPress page template with microdata

The code above will help WordPress to detect our custom template file when we edit our page later.

Step #4. Set product schema

We're going to use the schema that is described on Schema.org:

Now let's continue editing the page-product.php file.

Look for the containers and add itemscope itemtype="http://schema.org/Product", like this:

<div id="page-container" itemscope itemtype="http://schema.org/Product">

Now, look for the tag that wrapper the title, and add itemprop="name".

<h1 itemprop="name"><?php the_title(); ?></h1>

Inside the page container, add this snippet replacing the price, priceCurrency and availability contents with your own.

<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
    <meta content="9.99" itemprop="price" />
    <meta content="USD" itemprop="priceCurrency" />
    <meta content="instock" itemprop="availability" />

Below, add this microdata with the rating, replacing the ratingValue (from 1 to 5 stars) and ratingCount (number of reviews/votes) content with your own:

<div itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">
    <meta itemprop="ratingValue" content="5" />
    <meta itemprop="ratingCount" content="19" />

  • Click Update file button when you're done.

Adding Microdata to a WordPress file

Since every theme has its own way of structuring content, the result will be different. However, the end result will look similar to the image below:

A WordPress PHP file with microdata

Step #5. Edit your product page

  • Go to Pages > Your page.
  • Choose the Template, which in this example is "Page product".

Adding a template to a WordPress page

  • Click the Update button when you're done.

Step #6. End result

Try Step #1 again. This time the microdata should be displayed, and with patience, that information will be reflected in Google search results.

Googles structured data tool with microdata

About the author

Valentín creates beautiful designs from amongst the tequila plants of Jalisco, Mexico. You can see Valentín's design work all over this site and you can often find him helping members in support.