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.

add_action( 'get_header', 'themeprefix_cpt_microdata' );
//Change microdata for events custom post type
function themeprefix_cpt_microdata() {
if ('event' == get_post_type()) {//change to your cpt
//add in the microdata changes
add_filter( 'genesis_attr_entry', 'themeprefix_genesis_attributes_entry', 20 );
function themeprefix_genesis_attributes_entry( $attributes ) {
$attributes['itemtype'] = 'http://schema.org/Event';
return $attributes;
}
add_filter( 'genesis_attr_entry-title', 'themeprefix_genesis_attr_entry_title', 20 );
function themeprefix_genesis_attr_entry_title( $attributes ) {
$attributes['itemprop'] = 'event';
return $attributes;
}
add_filter( 'genesis_attr_entry-content', 'themeprefix_genesis_attributes_entry_content' , 20 );
function themeprefix_genesis_attributes_entry_content( $attributes ) {
$attributes['itemprop'] = 'description';
return $attributes;
}
}
}
view raw microdata-cpt.php hosted with ❤ by GitHub

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!

7 Comments

  1. Donovan on February 10, 2017 at 12:35 am

    Can you help me with something?

    I want to create a Custom Page/Post Template in Genesis using ‘Review’ schema and a custom field where I can add star rating and so on.

    How do I do this?

  2. berrada on January 24, 2016 at 2:34 pm

    From the time i moved to genesis html5 i lost all my images that were in google image search and even after the last update to genesis 2.2.6 it does not solve the problem.
    Worst other people are ranking for my images but not me.
    I think that even if we update to genesis latest Schema “creativework” it’s not sufficient because we need to update all this stuff via database.
    Also i checked new posts i’ve made after the update and images are still not displayed in the google structured data testing tool.
    Is it normal?

  3. Aaron on July 21, 2015 at 11:03 pm

    Thanks for this! It helped me change the microdata from blog to newsArticle. The only thing that is now missing is the featured image. Google says that image is required and missing. So my question is how to add itemprop=”image” into the featured images?

    • Alexander on October 30, 2015 at 9:21 pm

      i have the same question! any solution? 🙂

  4. Mark Law on July 1, 2015 at 5:49 am

    Thanks for posting this!, it is exactly what I was looking for! I’ve got a client that provides ‘treatments’ so instead of using the default Genesis ‘CreativeWork’ Schema for all custom post types I’m using the ‘Service’ Schema.

    It probably makes no difference, but hey it makes me feel good 🙂

  5. […] Some of the mark up can be added and edited by using filters to adjust the microdata schema code. […]

Leave a Comment





%d bloggers like this: