How to customize Twenty Thirteen for Google Authorship

Google searches which show your articles can include your photo by setting up Google Authorship. As instance, here is a search which returns a post of this site:

googleauthorship

Google Autorship is a very useful feature: it can increase your traffic significantly. So, I wanted to add it to this site: we are using WordPress and the Twenty Thirteen theme. Surprisingly, I did not find any information about customizing that theme for Google Authorhip, so I hope this post fills the void.

We assume that you already have a Twenty Thirteen’s child theme. You need to customize your functions.php file (or create it if it does not exist) as follows.

Step 1. Byline

We must write the byline somewhere. We exploit the already existing entry meta in order to give this information. If you look at the top of this post you can see my byline: ‘By Flavio Calva’. How do we obtain this? Open your functions.php file and add the following code.

[code language=”php”]if ( ! function_exists( ‘twentythirteen_entry_meta’ ) ) :
function twentythirteen_entry_meta() {
if ( is_sticky() && is_home() && ! is_paged() )
echo ‘<span class="featured-post">’ . __( ‘Sticky’, ‘twentythirteen’ ) . ‘</span>’;

if ( ! has_post_format( ‘link’ ) && ‘post’ == get_post_type() )
twentythirteen_entry_date();

// Translators: used between list items, there is a space after the comma.
$categories_list = get_the_category_list( __( ‘, ‘, ‘twentythirteen’ ) );
if ( $categories_list ) {
echo ‘<span class="categories-links">’ . $categories_list . ‘</span>’;
}

// Translators: used between list items, there is a space after the comma.
$tag_list = get_the_tag_list( ”, __( ‘, ‘, ‘twentythirteen’ ) );
if ( $tag_list ) {
echo ‘<span class="tags-links">’ . $tag_list . ‘</span>’;
}

// Post author
if ( ‘post’ == get_post_type() ) {
printf( ‘<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>’,
esc_url( get_author_posts_url( get_the_author_meta( ‘ID’ ) ) ),
esc_attr( sprintf( __( ‘View all posts by %s’, ‘twentythirteen’ ), get_the_author() ) ),
‘By ‘ . get_the_author_meta(‘first_name’) . ‘ ‘ . get_the_author_meta(‘last_name’)
);
}
}
endif;[/code]

We are defining the twentythirteen_entry_meta function. What is worth to note is the following line:

[code language=”php”]’By ‘ . get_the_author_meta(‘first_name’) . ‘ ‘ . get_the_author_meta(‘last_name’)[/code]

This actually defines the byline.

Step 2. Setting up the author tag

Now we have to add the author tag to the HTML header.

[code language=”php”]add_action(‘wp_head’, ‘wpse_43672_wp_head’);
function wpse_43672_wp_head(){
?>
<link rel="author" href="https://plus.google.com/<yourGooglePlusId>/posts"/>
<?php
}[/code]

Step 3. Time

Finally, we have to expose the updated field of hatom-entry.

[code language=”php”]if ( ! function_exists( ‘twentythirteen_entry_date’ ) ) :
function twentythirteen_entry_date( $echo = true ) {
if ( has_post_format( array( ‘chat’, ‘status’ ) ) )
$format_prefix = _x( ‘%1$s on %2$s’, ‘1: post format name. 2: date’, ‘twentythirteen’ );
else
$format_prefix = ‘%2$s’;

$date = sprintf( ‘<span class="date"><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date updated" datetime="%3$s">%4$s</time></a></span>’,
esc_url( get_permalink() ),
esc_attr( sprintf( __( ‘Permalink to %s’, ‘twentythirteen’ ), the_title_attribute( ‘echo=0’ ) ) ),
esc_attr( get_the_date( ‘c’ ) ),
esc_html( sprintf( $format_prefix, get_post_format_string( get_post_format() ), get_the_date() ) )
);

if ( $echo )
echo $date;

return $date;
}
endif;[/code]

Conclusion

The entire functions.php follows. I hope you found this post useful!

[code language=”php”]<?php
if ( ! function_exists( ‘twentythirteen_entry_meta’ ) ) :
function twentythirteen_entry_meta() {
if ( is_sticky() && is_home() && ! is_paged() )
echo ‘<span class="featured-post">’ . __( ‘Sticky’, ‘twentythirteen’ ) . ‘</span>’;

if ( ! has_post_format( ‘link’ ) && ‘post’ == get_post_type() )
twentythirteen_entry_date();

// Translators: used between list items, there is a space after the comma.
$categories_list = get_the_category_list( __( ‘, ‘, ‘twentythirteen’ ) );
if ( $categories_list ) {
echo ‘<span class="categories-links">’ . $categories_list . ‘</span>’;
}

// Translators: used between list items, there is a space after the comma.
$tag_list = get_the_tag_list( ”, __( ‘, ‘, ‘twentythirteen’ ) );
if ( $tag_list ) {
echo ‘<span class="tags-links">’ . $tag_list . ‘</span>’;
}

// Post author
if ( ‘post’ == get_post_type() ) {
printf( ‘<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>’,
esc_url( get_author_posts_url( get_the_author_meta( ‘ID’ ) ) ),
esc_attr( sprintf( __( ‘View all posts by %s’, ‘twentythirteen’ ), get_the_author() ) ),
‘By ‘ . get_the_author_meta(‘first_name’) . ‘ ‘ . get_the_author_meta(‘last_name’)
);
}
}
endif;

add_action(‘wp_head’, ‘wpse_43672_wp_head’);
function wpse_43672_wp_head(){
?>
<link rel="author" href="https://plus.google.com/<yourGooglePlusId>/posts"/>
<?php
}

if ( ! function_exists( ‘twentythirteen_entry_date’ ) ) :
function twentythirteen_entry_date( $echo = true ) {
if ( has_post_format( array( ‘chat’, ‘status’ ) ) )
$format_prefix = _x( ‘%1$s on %2$s’, ‘1: post format name. 2: date’, ‘twentythirteen’ );
else
$format_prefix = ‘%2$s’;

$date = sprintf( ‘<span class="date"><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date updated" datetime="%3$s">%4$s</time></a></span>’,
esc_url( get_permalink() ),
esc_attr( sprintf( __( ‘Permalink to %s’, ‘twentythirteen’ ), the_title_attribute( ‘echo=0’ ) ) ),
esc_attr( get_the_date( ‘c’ ) ),
esc_html( sprintf( $format_prefix, get_post_format_string( get_post_format() ), get_the_date() ) )
);

if ( $echo )
echo $date;

return $date;
}
endif;

?>[/code]