How to Add Schema Markup to a Page in WordPress

Add Schema Markup in WordPress

If you are operating a local business there is something you can do right now to gain an advantage over your competition. It is called schema markup. Taking advantage of this early on will benefit you. What is schema markup? Basically it is code you can add to your page so that search engines like Google and Bing can better identify the data and be more likely to serve that information up in SERPs.

[clickToTweet tweet=”Schema Markup is the Bees Knees! #schema #SERPs” quote=”Schema Markup is the Bees Knees! #schema #SERPs”]

There is a great article on KissMetrics about How to Boost Your SEO by Using Schema Markup. I suggest reading through that if you want to know more about how schema markup helps you and then come back to our page. I will show you how to quickly add some schema markup for a local business location to a page in WordPress.

There is a WordPress plugin out there called Schema Creator by Raven, however I was not happy with the results. There were a bunch of line breaks and I couldn’t get it to look like I wanted without going and editing the plugin itself. I needed to add location data, specifically the LocalBusiness attribute. So I asked my brother Brett who is a phenomenal PHP programmer and he whipped up something in a matter of minutes. So I thought I would share it with you as an alternative to using a plugin or simply pasting the HTML from a schema generator.

Step 1

First we are going to add a function for our schema itemtypes, specifically LocalBusiness and PostalAddress, to WordPress. So in your WordPress dashboard browse to Appearance and click on on “Editor.”

wordpress appearance editor

Step 2

Click into your WordPress functions.php file. (please don’t edit this file if you are unsure of what you are doing, or please make a backup first!)

wordpress functions file

Step 3

Now scroll to the bottom and we are going to add this code. What we are doing is creating a shortcode we can use later. Why do we do a shortcode? Simply because if you have multiple people editing sometimes they will switch out out of the text view and you lose your schema markup.

function shortcode_printaddress($atts)
$val.= '
<div itemscope itemtype="">';
$val.= '<a itemprop="url" href="' . site_url() . '">';
$val.= '
<div itemprop="name">';
$val.= '<strong>' . $atts["name"] . '</strong>';
$val.= '</div>

'; $val.= '</a>';
$val.= '
<div itemprop="address" itemscope itemtype="">';
$val.= '<span itemprop="streetAddress">';
$val.= $atts["address1"]; if(!empty($atts["address2"]))
$val.= '
' . $atts["address2"];
$val.= '</span>
$val.= '<span itemprop="addressLocality">' . $atts["city"] . '</span>, <span itemprop="addressRegion">' . $atts["state"] . '</span> <span itemprop="postalCode">' . $atts["zip"] . '</span>';
$val.= '</div>

$val.= '</div>

'; return
add_shortcode('printaddress', 'shortcode_printaddress');

Step 4

Now we can go to our page and add the shortcode. Obviously you will want to change the details below with your address.

[[printaddress name=”OKay Marketing” address1=”8275 E Bell RD” address2=”Suite 250″ city=”Scottsdale” state=”AZ” zip=”85260″]]

The shortcode will display like our address below.

OKay Marketing
8275 E Bell RD
Suit 250
Scottsdale, AZ 85260

The reason we like this method better is because it is much easier to style, there aren’t any line breaks and to the general user, it looks just like a normal address listing.

Step 5

Now you will want to copy the URL of the page you have the shortcode on and go test it in the Google Structured Data Testing Tool.

At the very bottom you will want to verify that you have the localbusiness item type and that the address points to Item 1 which in turn points to Item 1 for the address.

schema local business wordpress

There are many more things you could add too, like phone number, hours of business, etc. To read more about the available schema types visit the official schema website.

Get More Stuff Like This

Marketing, WordPress, Blogging Tips, SEO and Reviews, once a week.

Thank you for subscribing.

Something went wrong.

11 thoughts on “How to Add Schema Markup to a Page in WordPress”

  1. No it did not work. Yes, I copied the code correctly. Perhaps a little more detail into how we copy then paste to functions.php file. I copied, updated and received a script error.

    • If you paste it into the bottom and it gives you issues, usually that is because either you are missing a } at the end or you need to add a } at the end. Each functions.php file is different, but try adding one or without.

Leave a Comment