Since there are already so many great articles out there about the usefulness of adding Schema.org Microdata to your HTML5 markup, I’ll let Google help you out on that.
I encountered a situation where I needed to change all microdata for single blog posts, archive pages, home page and any other place a blog post was displayed.
Let’s get started:
When viewing a blog post there are several places that need attention, first in the <main> tag. Here, I wanted to change the itemtype from: http://schema.org/Blog to http://schema.org/CreativeWork.
With help around the web I tracked down: genesis>lib>functions>markup.php, this file outputs all the Genesis microdata. (It is helpful to open that file up and have a peek while you read this. )
The various filters in markup.php can be copied and pasted as they contain handy conditional functions to target the specific attributes I needed to change.
Here is the filter that targets the <main> tag:
add_filter( 'genesis_attr_content', 'genesis_attributes_content' );
We just have to create our own filter and function to replace the Genesis one, then paste in the conditional for Blog Microdata and customize it:
add_filter( 'genesis_attr_content', 'my_genesis_microdata_schema', 20 ); function my_genesis_microdata_schema( $attributes ){ //* Blog microdata if ( is_singular( 'post' ) || is_archive() || is_home() || is_page_template( 'page_blog.php' ) ) { $attributes['itemtype'] = 'http://schema.org/CreativeWork'; //changed from: Blog to CreativeWork } return $attributes; }
The next step is moving on to change the microdata in the <article> tag.
It is the next filter down in markup.php:
add_filter( 'genesis_attr_entry', 'my_genesis_attributes_entry' ); //this one is already customized
Again, copy and paste the function and modify it to suit.
function my_genesis_attributes_entry( $attributes ) { //* Blog posts microdata if ( 'post' === get_post_type() ) { $attributes['itemtype'] = 'http://schema.org/Article'; //changed from BlogPosting //* If main query, if ( is_main_query() ) $attributes['itemprop'] = 'NewsArticle'; //changed from blogPost } return $attributes; }
Obviously, the attributes can be whatever is needed to suit a particular application. The combination of these two filters will change all instances of Blog, BlogPosting, and blogPost to your custom microdata anywhere a regular WordPress post is displayed.
Note: If you need to target the BODY tag use this:
add_filter( 'genesis_attr_body', 'my_genesis_attributes_content' );
Checkout Schema.org for a list of available attributes.
Cheers,
Aaron
The post Change the Default Schema.org Microdata in Genesis appeared first on Aaron Jerad Designs.