Social Media Magazine

Solution To Wrong Author Page Title With Yoast SEO And Co-Authors Plus Plugin

Posted on the 23 June 2017 by Pro Webguru @prowebguru

Recently I was working on a wordpress multisite project. And one day we noticed an issue where Authors page was showing correct information except author page title. So Author information on page was correct but author page title was showing some other user name.
Then we did some analysis and found that it was issue with Yoast SEO and Co-Authors Plus plugin.

This is one of the best plugin to use with wordpress. I have been using this plugin from quite a long time and it's awesome. It has lot of features like

  1. Page Analysis
  2. Meta title rewrite
  3. Xml sitemaps
  4. Rss optimization
  5. Breadcrumb
  6. Edit .htaccess and robots.txt file
  7. Multisite compatible
  8. Import Export options
  9. And many more features.

This plugin is very useful if you want to add Guest Authors to your WordPress site but don't want to create a wordpress user account. This plugin is very useful as it allows you to add guest authors in wordpress.

We started using these 2 plugins as per our requirements. But then one of the tester found out issue - Author titles for Guest Authors created using Co-Authors Plus plugin were not showing correctly on Author biodata page. All other page contents were correct.

Also I had Yoast SEO plugin installed which I am using for rewriting titles of different pages. Author title information was rewritten correctly but Author name was wrong.

After doing some debugging, I found that it was issue with how Yoast SEO. Basically Co-Authors plus creates a guest author and that information is somehow missed while rewriting author page titles.

But Yoast SEO is awesome plugin and it does provide some hooks if you want to write some custom code to integrate with Yoast SEO plugin.

What is a hook ?

As per WordPress Codex

Hooks are provided by WordPress to allow your plugin to 'hook into' the rest of WordPress; that is, to call functions in your plugin at specific times, and thereby set your plugin in motion.

There are 2 types of hooks

Basically it allows you to inject some of your custom code into wordpress plugin or theme.

Yoast SEO plugin provides lot of hooks with which you can play with. You can find list of hooks provided by Yoast SEO here.

We are going to use " wpseo_title " filter to fix wrong page titles shown through Yoast SEO plugin when using Co-Authors Plus plugin.

Wpseo_title filter allows us to modify title which is shown on the page. Following is the code which I have put in "functions.php" file of my theme.
/*Fliter to modify the author display name on author page title for co-authors plus guest authors.*/
/*Solution for issue with yoast seo and co-authors plus guest author name reading for title of author page.*/

add_filter( 'wpseo_title', 'filterAuthorTitle' );
function filterAuthorTitle( $title ) {
//check if author page, if it's not return as it is
if ( ! is_author() ) {
return $title;
}
//its author page, so let's pull current author name
$current_display_name = get_the_author_meta( 'display_name', get_query_var( 'author' ) );
$authorobj = get_queried_object();
$new_display_name = $authorobj->display_name ;
return str_replace( $current_display_name, $new_display_name, $title );
}

Please let me know if this solution worked for you or not. Or did you find any other way to fix wrong titles on author page when using Yoast SEO and Co-Authors Plus plugin.

Do share it with your friends if you find it useful.


Back to Featured Articles on Logo Paperblog