DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Building Scalable Real-Time Apps with AstraDB and Vaadin
Register Now

Trending

  • Revolutionizing Algorithmic Trading: The Power of Reinforcement Learning
  • Operator Overloading in Java
  • Tomorrow’s Cloud Today: Unpacking the Future of Cloud Computing
  • Cypress Tutorial: A Comprehensive Guide With Examples and Best Practices

Trending

  • Revolutionizing Algorithmic Trading: The Power of Reinforcement Learning
  • Operator Overloading in Java
  • Tomorrow’s Cloud Today: Unpacking the Future of Cloud Computing
  • Cypress Tutorial: A Comprehensive Guide With Examples and Best Practices

How to Add Schema.org to Your WordPress Theme

Paul Underwood user avatar by
Paul Underwood
·
Oct. 23, 13 · Interview
Like (0)
Save
Tweet
Share
7.40K Views

Join the DZone community and get the full member experience.

Join For Free

All of the major search engines Google, Yahoo and Bing got together to come up with a way webmasters can better define the content on the page to give search engines more information about what they are crawling. Understanding the content of the page allows the search engines to display more information in the search results. Adding more information in the search results makes it easier for users to find what they want can greatly increase your click through rates in the search engines.

As all the major search engines have agreed on the markup, this makes it easier to implement schema.org and get the benefits from all search engines.

Schema.org allows you to define the information on the page there are many different types such as:

  • Movies
  • Books
  • Recipes
  • Video
  • Audio
  • Events
  • Organisation
  • Person
  • Place
  • Review

There are lots more types you can define the page to be, here is the full list.

Full Schema.org Types

Structured Data Snippets

To see how this affects your search results in Google, you can get more information about rich snippets in Google Webmaster tools.

From this image, you can see how different these snippets appear in the search results.

webmasters_99170_rsreview_en

For events, you can make the event dates appear in the search results. For movies, you can make a rating or reviews appear in the search results. For a music album, you can make the track list appear in the search results.

How to Use Schema.org

To use schema.org you just have to add a bit more markup to your HTML, this is to tell the search engines what the page is about and what specific items of the page are.

Below is an example of defining a movie in your HTML markup. This starts by finding the outer containing element and defining it as the type of content you are explaining by using the attributes itemscope and itemtype.

<div itemscope itemtype="http://schema.org/Movie">

</div>

Each of the elements in the movie can be defined by using the attribute itemprop. To define the name of the movie you just need to add itemprop="name" to the header tag.

<h1 itemprop="name">Avatar</h1>

Inside the movie element you can also define the director, the genre and a link to the trailer of the movie. Here is the full HTML markup to define a movie area.

<div itemscope itemtype="http://schema.org/Movie">
  <h1 itemprop="name">Avatar</h1>
  <div itemprop="director" itemscope itemtype="http://schema.org/Person">
  Director: <span itemprop="name">James Cameron</span> (born <span itemprop="birthDate">August 16, 1954)</span>
  </div>
  <span itemprop="genre">Science fiction</span>
  <a href="../movies/avatar-theatrical-trailer.html" itemprop="trailer">Trailer</a>
</div>

What To Use In WordPress

To use schema.org in WordPress, you need to change your theme with the markup required to define the content of your site. With WordPress this can easily be done, as we know the content types of each template file that will be used.

In the HTML tag of your theme, you should add a new function to output the item type of the page.

<html <?php html_tag_schema(); ?> <?php language_attributes(); ?>>

In your functions.php file, add the following function to automatically define the schema type you want to use for the type of content.

function html_tag_schema()
{
    $schema = 'http://schema.org/';

    // Is single post
    if(is_single())
    {
        $type = "Article";
    }
    // Contact form page ID
    else if( is_page(1) )
    {
        $type = 'ContactPage';
    }
    // Is author page
    elseif( is_author() )
    {
        $type = 'ProfilePage';
    }
    // Is search results page
    elseif( is_search() )
    {
        $type = 'SearchResultsPage';
    }
    // Is of movie post type
    elseif(is_singular('movies'))
    {
        $type = 'Movie';
    }
    // Is of book post type
    elseif(is_singular('books'))
    {
        $type = 'Book';
    }
    else
    {
        $type = 'WebPage';
    }

    echo 'itemscope="itemscope" itemtype="' . $schema . $type . '"';
}

Because the title tag is normally the same as the headline of the page, you can add the name itemprop to the HTML title tag.

<title itemprop="name"><?php wp_title(''); ?></title>

To define the main content area of your site, find the div that wraps around the the_content() function and add the itemprop mainContentOfPage around the content area.

<div id="content" itemprop="mainContentOfPage">
	<?php the_content();?>
</div>

To let the search engines know when an article was published or modified, you can use schema.org to define these two settings. On most articles, you will define when the article was published, add an itemprop of datePublished to the date element.

<time class="entry-date" datetime="<?php the_date('F jS, Y'); ?>" itemprop="datePublished" pubdate><?php the_date('F jS, Y'); ?></time>

If you are using custom post types for movies or books then you can can define the different itemprops in the custom post type template files.

All this will allow you to tell the search engines exactly what part of the page is the specific content you want to highlight. Allowing search engines to know who the author was, when the page was changed, the main content for the page and much more.

Schema.org WordPress Engine

Published at DZone with permission of Paul Underwood, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Revolutionizing Algorithmic Trading: The Power of Reinforcement Learning
  • Operator Overloading in Java
  • Tomorrow’s Cloud Today: Unpacking the Future of Cloud Computing
  • Cypress Tutorial: A Comprehensive Guide With Examples and Best Practices

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: