How to add Schema Markup for WordPress Blog with Multi Authors

Last week i covered a WordPress tutorial on How to add Schema Markup to WordPress Theme but it only work with WordPress blog with only one author. How about a blog with multiple authors? Today i am going to teach you how to add schema markup for WordPress blog with multiple authors.

First and important, the authors and guest blog writers of your site must go to their Google+ profile -> about -> links and add Contributor to and add your site url to the contributor list.

Step 1 – Add Each Author Google+ Profile settings

open your WordPress theme’s functions.php and add this code

if( !function_exists( 'mp_custom_userfields' ) ):
// add custom user field
function mp_custom_userfields( $contactmethods ) {
$contactmethods['user_twitter']     = 'Twitter URL';
$contactmethods['user_facebook']    = 'Facebook URL';
$contactmethods['user_googleplus']  = 'Google Plus URL';
$contactmethods['user_linkedin']    = 'Linkedin URL';
return $contactmethods;

As you can see, this will add an extra field in WordPress user profile (wp-admin/profile.php)

Now each authors/contributors to your site will be able to add their own Google+ Profile URL.

Step 2 – Adding the schema template

Create a blank php and name it schema.php and add this code into it

<!-- #start Article Schema Markup for WordPress with multi authors -->

<div style="width:10px;height:10px;position:absolute;left:-9999em" class="post-schema">

global $post;
$author_email = get_the_author_meta('user_email');
$author_displayname = get_the_author_meta('display_name');
$author_nickname = get_the_author_meta('nickname');
$author_firstname = get_the_author_meta('first_name');
$author_lastname = get_the_author_meta('last_name');
$author_url = get_the_author_meta('user_url');
$author_status = get_the_author_meta('user_level');
$author_description = get_the_author_meta('user_description');

// get the user roles
$user_roles = 'Subsribers';
$user_roles = 'Contributor';
$user_roles = 'Author';
$user_roles = 'Editor';
$user_roles = 'Administrator';

// get user google+ profile
$author_googleplus_profile = get_the_author_meta('user_googleplus');

// get post thumbnail
$thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "thumbnail" );

<!-- Insert data:Article schema -->
<article itemscope="" itemtype="">

<span class="entry-title" itemprop="name headline"><a itemprop="url" href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></span>

<!-- Insert data:Article:image schema -->
<?php if($thumbnail_src): ?>
<span itemprop="image"><?php echo $thumbnail_src[0]; ?></span>
<?php endif; ?>

<!-- Insert data:Article:Published schema -->
<time datetime="<?php the_time('Y-m-d') ?>" itemprop="datePublished"></time>
<time datetime="<?php the_modified_time('d F Y') ?>" class="entry-date updated"></time>

<!-- Insert data:Article:Author schema -->
<span class="vcard author"><span class="fn"><?php the_author(); ?></span></span>

<!-- Insert data:Article:ArticleSection schema -->
$categories = get_the_category();
$separator = ', ';
$output = '';
foreach($categories as $category) {
echo '<span style="display:none;" itemprop="articleSection">' . $category->cat_name . '</span>';

<!-- Insert data:Article:Tag schema -->
<?php if( has_tag() ) { ?>
<span itemprop="keywords"><?php the_tags('', ','); ?></span>
<?php } ?>

<!-- Insert data:Article:Content schema -->
<?php if( !is_singular() ): ?>
<div itemprop="description"><?php the_excerpt(); ?></div>
<?php else: ?>
<div itemprop="articleBody"><?php the_content(); ?></div>
<?php endif; ?>

<!-- Insert data:Person schema -->
<span itemprop="author" itemscope="" itemtype="">

<!-- Insert data:Person:Author schema -->
<span itemprop="name">
<a href="<?php echo $author_googleplus_profile; ?>?rel=author" itemprop="url">
<?php echo $author_displayname; ?></a>

<!-- Insert data:Person:others schema *optional -->
<span itemprop="givenName"><?php echo $author_firstname; ?></span>
<span itemprop="familyName"><?php echo $author_lastname; ?></span>
<span itemprop="email"><?php echo $author_email; ?></span>
<span itemprop="jobTitle"><?php echo $user_roles; ?></span>

<?php if($author_description): ?>
<span itemprop="knows"><?php echo stripcslashes($author_description); ?></span>
<?php endif; ?>

<span itemprop="brand"><?php echo bloginfo('name'); ?></span>

<!-- end data:Person schema -->



<!-- #end Article Schema Markup for WordPress with multi authors -->
Download the schema.php here
File Format: zip   File Size: 1.25KB

Step 3 – Adding created schema.php into post_loop()

Upload the schema.php into your current theme root (wp-content/themes/current-theme/)
Open any file with post_loop (index.php, home.php, archive.php or single.php) and add this code

<?php get_template_part('schema'); ?>

to post_loop() like this

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<!-- your own existed loop code -->
<!-- add this below -->
<?php get_template_part('schema'); ?>
<?php endwhile; else: ?> <?php endif; ?>

Step 4 – Testing the result

if everthing completed, run the test with Structured Data Testing Tool and test the single post url for each author.

If your site author already add your site url into their Google+ profile -> about -> links -> Contributor to then everything should be ok, if not warning message like

Authorship not verify with the please verify…

will appeared in the snippet testing result.

Ok, that’s all the step needed to add schema to your multi author WordPress blog. Hope you enjoy the read and if you have any comments regarding the tutorial, feel free to comment here.

On Other Note

Some question rise about is it necessary to use Google+ profile for rel=author?. The answer is simply yes, Google need to gather the author verification and data so the schema can work but in the other hand, there’s an article about no verification needed that you might found interesting to read and explore the possibility.