Using schema.org metadata for WordPress SEO

What is schema.org metadata?

If you have used Google Webmaster Tools and have explored the various options one that most likely stuck out to you was the Structured Data option in the menu for your blog. If you are lucky you installed a theme that was developed with the proper schema.org metadata tags already in place and used correctly. If this is the case when you click on this option in the Webmaster Tools you will see no errors and Google happily indexing your metadata. However, the more likely case is that you will notice some errors here. This is not to say that the theme developer did a poor job or didn’t know what they were doing. Unfortunately many of the themes currently available through the WordPress site do not have the proper metadata tags in place. While having errors or not having the proper tags will not necessarily hurt your search rankings, having them and having them implemented correctly can make a big difference for you, especially if your keywords are highly competitive. If you are running an ecommerce site properly implemented metadata can help your individual products get indexed far more quickly and properly by search engines.

So enough of that, what is metadata and what is the schema.org metadata? Schema.org metadata is an extra set of tags that you can add to your HTML elements to let the search engines know specifically what that element contains. For example, for a blog post, you would tag the title as a headline, the author as an author, and the date the blog post was published as the publishedDate. Now when Google indexes your site it knows specifically what the title of an article is, who the author is, and when the post was published without any further assistance or having to try and figure it out for itself. In addition, for media attachments such as videos and images you can tag them as well to give Google and other search engines specific information about the image or video that may not be readily available.

But why schema.org, aren’t there other formats available? Yes there are other formats available, but the schema.org tags and format have become the standard to some extent across all the search engines. With the schema.org tags you can be assured that your data will be widely recognized.

How to include schema.org metadata in your WordPress blog

While the entire schema.org metadata library is quite extensive and there are hundreds of options, I am going to just cover the basics for including the schema.org metadata with your standard WordPress blog. I will not go in depth into covering how to configure products or an e-commerce site, however, you should be able to garner the necessary knowledge from this article and easily combine it with details from the schema.org website to implement the proper metadata into your site.

If you are developing your own theme, then implementing the schema.org metadata will be easy. If you are trying to incorporate schema.org metadata into a theme you downloaded or purchased from somewhere else you may find this a little challenging. Luckily, there are several plugins out there such as the All-In-One Schema.org Rich Snippets plugin that will help you get this all setup. Just a note of caution that some of these plugins can add the wrong data in the wrong spots resulting in violations to the Google Webmaster Guidelines or problems with the markup in general. If you are comfortable with PHP and navigating your way around WordPress theme files I would recommend implementing the necessary code yourself as you can tweak it just right to be sure it aligns with the content of your blog instead of relying on a plugin to do it for you.

First things first, let’s add metadata to tell what our pages are. There are a couple options here. You can take the simple route and just mark each page as a type WebPage. The other option is a little more complex and requires you to add a function and identify specific pages as specific types. Whichever you choose is completely up to you, but I guess to be thorough and if you are starting with a theme you are developing yourself you can take the more advanced route. I am going to show both options here:

Option 1 (easy): In your header.php file you are going to edit the body element to include the following:

That’s it, you have now identified each page of your WordPress blog as type WebPage using schema.org metadata. Seems easy enough…don’t go getting to excited though there is a bunch more to go.

Option 2 (advanced): The schema.org metadata allows you to identify specific pages as specific types. For example, you can identify your about page as an AboutPage and your contact page as a ContactPage. Sounds good, but how do you do that exactly? Well here is where it gets a little tricky. If you are developing a theme for others you may be best just going with option 1 above. However, if the theme you are working on is for yourself or you altering an existing theme for yourself then this is a little easier.

First, instead of adding the itemscope/itemtype tags into our body element we are going to add a function instead. For example:

1

&lt;body&lt;?php yourtheme_metadata_function();?&gt;&gt;

Then in your functions.php file you will add a function as such (thanks to Felix Arntz for this function):

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

functionyourtheme_metadata_function(){

$base='http://schema.org/';

if(is_page(5/* type in the ID of your contact page here, 5 is an example */))

{

$type='ContactPage';

}

elseif(is_page(4/* type in the ID of your about page here, 5 is an example */))

{

$type='AboutPage';

}

elseif(is_singular(array('book','movie')/* add custom post types that describe a single item to this array */))

{

$type='ItemPage';

}

elseif(is_author())

{

$type='ProfilePage';

}

elseif(is_search())

{

$type='SearchResultsPage';

}

else

{

$type='WebPage';

}

echo'itemscope="itemscope" itemtype="'.$base.$type.'"';

}

You will notice above that you will have to edit the function to include the specific numbers to specific pages though. This is where if you are developing the theme for someone else you will not know the exact numbers and will have to account for that. While there are ways to handle this, I am just showing you this as an example that you can build on if needed.

So now that we have defined our page types we need to start identifying specific information. Like I said above there are multiple options here and I am just going to cover some of the basics. For more an in-depth discussion and complete explanation of the various schema.org itemtypes available you can visit http://schema.org/docs/schemas.html.

While we are in the header.php we might as well go ahead and markup the WordPress blog title. Find the element for your blog title as such:

1

&lt;title&gt;

and change it to:

1

&lt;title itemprop="name"&gt;

Go ahead and save the header.php. Now we are going to move on to marking up the content itself. This part is probably going to vary greatly from theme to theme since every developer has their own way of implementing specific code into their themes. Some may prefer using functions to generate the underlying code, while others may just make it easy and place the code directly into respective theme files. I am going to go with the basics here and assume that the code is laid out cleanly in each theme file. Although if the developer uses functions it is just as easy to navigate your way through the function files to determine what you need to markup (plus doing it once in a function file saves having to go through multiple files and ensures consistency). Either way you will get the idea from here.

I am going to use the main content.php file as a starting example, but note that you will have to make similar changes to any other post format/type pages, your page files, search.php, archive.php, taxonomies.php, tags.php, author.php, etc.. pages.

At the first div element for the content itself (i.e. <div id=”content”> or in some cases this may be an article element depending on the theme developer) we are going to add the following changes (note that you may have other tags in the element, you will want to leave them as is and just add the necessary code from below):

Next move on to the date. You probably have something similar to the following:

1

&lt;time class="entry-time"&gt;

change this to the following:

1

&lt;time class="entry-time"itemprop="datePublished"&gt;

There are a couple other options you can include here such as identifying post categories and tags.

To identify categories we are going to make the following changes. You should have something that looks like this around your categories section:

1

&lt;span class="entry-terms category"&gt;

Just add:

1

&lt;span class="entry-terms category"itemprop="articleSection"&gt;

For the tags instead of the articleSection property you are going to add itemprop=”keywords”.

While there are plenty more tags you can add and use to identify specific elements within your blog, these basic elements will help greatly with allowing search engines such as Google to index your site and understand what specific parts of your site are about. For more information on schema.org you can check out the website at http://schema.org.

Testing your schema.org markup

Ok, so you have gone through your theme and marked up everything you think needed marked up, now how do you know what you did was right and that Google can understand it? Google has been kind enough to provide a free tool to test your microdata tags and tell you immediately what it can read from your markup. To utilize the tool simply log in to your Webmaster Tools account, click on the Other Resources link on the left side, and select the Structured Data Testing Tool. If your WordPress blog is publicly available you can simply enter your URL in to the box and click the Preview button. Google will fetch the page and show you what it can read. The tool will also tell you if you have Google Authorship or Google Publisher markup configured properly.

Born in Maryland, lives in Delaware, Starbucks addict, student, entrepreneur, and information technology professional. Jeff has been passionate about computers, technology, and the Internet since before he can remember. He blogs about programming and technology in general. Read more about Jeff Mould or follow him on Twitter.