Changing the Microdata Schema in Genesis WordPress

Genesis Themes come preloaded with Microdata schema marked up on various HTML elements on the page, this is a good thing in terms of meaningful and semantic markup and better structure for search engines to understand the page and extract certain data to present to searchers.

How Google displays search data to searchers is constantly changing which makes it even more important that the mark up is fully juiced with microdata schema to take full advantage of what is returned to the searcher, think of how data could be returned on sites that cover recipies, movies, songs etc

Microdata Attributes; itemscope and itemtype

What Microdata essentially does is give the content more meaning in terms of what it actually is. Various HTML elements of the page in current Themes have certain microdata injected into them as attributes inside the elements. These attributes are hierarchal and have a parent/child relationship, they create a new scope; itemscope, give it a defined type of content; itemtype, then specific elements; itemprop.

For example the sidebar which is marked up as an aside has 2 microdata attributes added, itemscope and itemtype:

<aside class="sidebar sidebar-primary widget-area" role="complementary" itemscope="itemscope" itemtype="http://schema.org/WPSideBar">...</aside>

The itemscope attribute  is making a statement saying that this piece of content is a unique scope and inside will be content belonging to it of a certain type, this type has an attribute of itemtype and its value is a URL which is defined in schema.org

 Microdata Attributes; itemprop

The 3rd level microdata attribute itemprop is content of the itemtype, looking at the sidebar example if you look at the value of the itemtype at http://schema.org/WPSideBar you can see all the itemprop values that can be used to describe the data.

There are no itemprop attributes/values defined in the sidebar but you could add itemprop values in any content added via widgets etc.

Default Genesis Microdata Output

You can see all the default microdata mark up of all elements in the following file:
genesis/lib/functions/markup.php

For example the sidebar example is contained between lines 713-732:

add_filter( 'genesis_attr_sidebar-primary', 'genesis_attributes_sidebar_primary' );
/**
 * Add attributes for primary sidebar element.
 *
 * @since 2.0.0
 *
 * @param array $attributes Existing attributes.
 *
 * @return array Amended attributes.
 */
function genesis_attributes_sidebar_primary( $attributes ) {

	$attributes['class'] = 'sidebar sidebar-primary widget-area';
	$attributes['role'] = 'complementary';
	$attributes['itemscope'] = 'itemscope';
	$attributes['itemtype'] = 'http://schema.org/WPSideBar';
	
	return $attributes;
}

There are just under 4o structural elements that have various microdata attributes applied to them. These have been marked up well and will work for most sites, but if you have a need to change the defaults then it can be done via a filter or a plugin.

 Changing the Genesis Microdata via a filter

add_filter( 'genesis_attr_sidebar-primary', 'themeprefix_genesis_attributes_sidebar_primary', 20 );

function themeprefix_genesis_attributes_sidebar_primary( $attributes ) {

	$attributes['itemscope'] = 'itemscope';
	$attributes['itemtype']  = 'http://schema.org/WPSideBar';
	$attributes['itemprop']  = 'award';

	return $attributes;

}

So the filter is added in your child themes function.php file, in the above example the same code from markup.php is used but the function name has a prefix and a later priority (20) so it is filtered after the initial filter. In this example the attribute itemprop is added to the markup and given a value of award. This is to show how to add attributes, the award itemprop is not really valid in this markup.

If you wanted to remove all the microdata from this element you would return no values:

add_filter( 'genesis_attr_sidebar-primary', 'themeprefix_genesis_attributes_sidebar_primary', 20 );

function themeprefix_genesis_attributes_sidebar_primary( $attributes ) {

	$attributes['itemscope'] = '';
	$attributes['itemtype']  = '';
	$attributes['itemprop']  = '';

	return $attributes;

}

Changing the Microdata on a Custom Post Type

To change the microdata on a custom post type where this would be most likely you can use the same filter as above but use it with a conditional argument to only change if the custom post type belongs to the one you are targetting.


So here the event custom post type is selected which actually has a valid schema and has its itemtype set to Event, also in this instance the headline will be the event name of the event and now that also has the itemprop value set . To fully complete the custom post type change all the relevant schema markup to the schema required. Also added here is the itemprop of description which will be the main text describing the event.

 Changing the Genesis Microdata via plugin

Brad Potter has a Genesis plugin that adds custom fields in post and pages in the post editor of the dashboard that allows you to overwrite the default microdata on certain itemtypes and itemprops. Find the right schema at schema.org that you feel is more appropriate to describe your content.

change-microdata-schema

 

What Content should use Microdata Schema

Not all content needs schema but relevant content like books, movies, events, recipes, video and audio are worthy of it, here is a full list of what schemas are available.

Checking your Schema mark up

You can check your schema markup over at Googles structure data testing tool to check it’s looking good!