How to add Schema Markup for WordPress Blog with Multi Authors

Schema Markup for WordPress Blog

Last week i covered a WordPress tutorial on How to add Schema Markup to a WordPress Theme, but it only works 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 a WordPress blog with multiple authors.

First and important, your site’s authors and guest blog writers 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’s Google+ Profile settings

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

[php]if( !function_exists( ‘mp_custom_userfields’ ) ):
//////////////////////////////////////////////////////////////////////////////
// add custom user field
/////////////////////////////////////////////////////////////////////////////
function mp_custom_userfields( $contactmethods ) {
// ADD CONTACT CUSTOM FIELDS
$contactmethods[‘user_twitter’] = ‘Twitter URL’;
$contactmethods[‘user_facebook’] = ‘Facebook URL’;
$contactmethods[‘user_googleplus’] = ‘Google Plus URL’;
$contactmethods[‘user_linkedin’] = ‘Linkedin URL’;
return $contactmethods;
}
add_filter(‘user_contactmethods’,’mp_custom_userfields’,10,1);
endif;
[/php]

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

extra field in the WordPress user profile

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
[php]
<!– #start Article Schema Markup for WordPress with multi authors –>

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

<?php
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
if($author_status==’0′):
$user_roles = ‘Subsribers’;
elseif($author_status==’1′):
$user_roles = ‘Contributor’;
elseif($author_status==’2′):
$user_roles = ‘Author’;
elseif($author_status==’7′):
$user_roles = ‘Editor’;
elseif($author_status==’10’):
$user_roles = ‘Administrator’;
endif;

// 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=”http://schema.org/Article”>

<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 –>
<?php
$categories = get_the_category();
$separator = ‘, ‘;
$output = ”;
if($categories){
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=”http://schema.org/Person”>

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

<!– 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>

</span>
<!– end data:Person schema –>

</article>

</div>

<!– #end Article Schema Markup for WordPress with multi authors –>
[/php]

[notice type=”downloads”]Download the schema.php here
File Format: zip   File Size: 1.25KB[/notice]

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]<?php get_template_part(‘schema’); ?>[/php]

to post_loop() like this

[php]<?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; ?>[/php]

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

[notice type=”error”]Authorship not verify with the www.domain.com. please verify…[/notice]

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 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.

Scroll to Top