› Using Schema.org shortcodes for WordPress

Using Schema.org shortcodes for WordPress

Email this to someoneShare on Facebook0Share on Google+0Share on LinkedIn0Share on Tumblr0Share on StumbleUpon0Tweet about this on TwitterShare on Reddit0Pin on Pinterest0

A lot of people seem confused and overwhelmed by microdata — and that’s understandable. There are a lot of conflicting standards and issues to work out.

But the bottom line is Google/Microsoft, etc. seem to have settled on the scheme.org standard, and despite a few kinks, it looks like the way to go moving forward.

I think using microdata in the future will be important. If properly implemented over a majority of the Web, it could do wonders to search engines and applications like Web browsers understand the type of content on your page, which can ultimately help users.

I think we need to have a broader discussion about this in the WordPress community. What better of  a way is there to start? WordPress powers some 15 percent of the world’s top million websites, and we have to start somewhere.

But going even further, I think the best way to integrate this across the Web is to add the features directly to visual editors — WYSIWYG editors like TinyMCE, CKeditor and others are used by so many to publish content…it’s probably the best place to start.

How about a little button in TinyMCE that lets you add the schema.org markup for a person’s name, job title, region, etc.? The same could apply for organization and product-related markup.

In the mean time, WordPress shortcodes could bridge the gap. So I’ve created a basic set of functions that lets one use minimal schema.org markup with WordPress shortcodes.

So I’ve created a repository at Github. Right now it only includes “name (Person),” address, city (region) and state:

https://github.com/edwardr/WordPress-Microdata

Basically, to use the shortcodes, you’ll just drop the PHP below in your functions.php file:

<?php
// Schema Type People

function edwardr_person_name($atts, $content = '', $code = NULL) {
	return '<span itemscope itemtype="http://schema.org/Person">
	<span itemprop="name">'. $content. '</span>
	</span>';
}
add_shortcode('name', 'edwardr_person_name');

// Schema Type Address

function edwardr_address_locality($atts, $content = '', $code = NULL) {
	return '<span itemscope itemtype="http://schema.org/PostalAddress">
	<span itemprop="addressLocality">' .$content. '</span>';
}
add_shortcode('city', 'edwardr_address_locality');
   
function edwardr_address_region($atts, $content = '', $code = NULL) {
	return '<span itemscope itemtype="http://schema.org/PostalAddress">
	<span itemprop="addressRegion">' .$content. '</span>
	</span>';
}
add_shortcode('state', 'edwardr_address_region');
   
function edwardr_address_street($atts, $content = '', $code = NULL) {
	return '<span itemscope itemtype="http://schema.org/PostalAddress">
	<span itemprop="streetAddress">' .$content. '</span>
	</span>';
}
add_shortcode('address', 'edwardr_address_street');

Here’s an example of how you’ll mark up related content using the shortcodes:

Scheme Shortcodes Markup

And here is the data Google will be able to pull from it:

Structured Data

Subscribe for weekly tutorials