Open gregarios opened 6 years ago
I noticed this issue as well, and have temporarily hidden my guest authors from my sitemap until I can get this resolved. Here's what I'm seeing in both my sitemap and Google Search Console.
Thank you for reporting this bug. I've assigned someone to further investigate the issue to check if we are able to solve this.
Related #6343. I think this needs... Work. Not sure if it needs work on our side. I'll reach out to one of the devs of CoAuthor Plus on WP Slack (@danielbachhuber).
Hi folks,
I'm no longer actively involved with Co-Authors Plus development. I'd suggest creating an issue in https://github.com/automattic/co-authors-plus/issues
Hey any updates on this? I don't see any open issues about this over in the above repo. I can open one if we still need it.
Hey any updates on this? I don't see any open issues about this over in the above repo. I can open one if we still need it.
It looks like the Yoast SEO doesn't even make a sitemap for the "guest authors" now, so while the links are not broken, they no longer even exist for me (which is better than broken). However, I would love for it to work again like it did years ago.
@gregarios It's because CPT guest-author isn't publicly queryable. You could enable it with this snippet:
function cpt_guest_authors_sitemap( $post_types ) {
$post_types['guest-author'] = 'guest-author';
return $post_types;
}
add_filter( 'wpseo_accessible_post_types', 'cpt_guest_authors_sitemap' );
Next step is adding filter wpseo_xml_sitemap_post_url
for changing URLs. If you want to test (and current code works for you) then I could try to make it. Also, we could submit PR in Co-Authors repo.
@gregarios It's because CPT guest-author isn't publicly queryable. You could enable it with this snippet:
function cpt_guest_authors_sitemap( $post_types ) { $post_types['guest-author'] = 'guest-author'; return $post_types; } add_filter( 'wpseo_accessible_post_types', 'cpt_guest_authors_sitemap' );
Next step is adding filter
wpseo_xml_sitemap_post_url
for changing URLs. If you want to test (and current code works for you) then I could try to make it. Also, we could submit PR in Co-Authors repo.
Your code does make the co-authors sitemap appear in the list, but I'm not sure what to do with your instruction for the wpseo_xml_sitemap_post_url filter. All the links in the sitemap are broken because they all look like the attached image:
All the links in the website are in the normal format: https://wshv.net/author/author-name/
Filter wpseo_xml_sitemap_post_url
should rewrite author URL. I created following snippet and I'm still checking how it works:
add_filter( 'wpseo_xml_sitemap_post_url', 'myseo_sitemap_guest_author_url', 10, 2 );
function myseo_sitemap_guest_author_url( $url, $author ) {
if ( is_object( $author ) && $author->post_type === 'guest-author' ) {
$user_nicename = preg_replace( '`^cap-`', '', $author->post_name );
$url = get_author_posts_url( $author->ID, $user_nicename );
}
return $url;
}
Please test if you can.
Filter
wpseo_xml_sitemap_post_url
should rewrite author URL. I created following snippet and I'm still checking how it works:add_filter( 'wpseo_xml_sitemap_post_url', 'myseo_sitemap_guest_author_url', 10, 2 ); function myseo_sitemap_guest_author_url( $url, $author ) { if ( is_object( $author ) && $author->post_type === 'guest-author' ) { $user_nicename = preg_replace( '`^cap-`', '', $author->post_name ); $url = get_author_posts_url( $author->ID, $user_nicename ); } return $url; }
Please test if you can.
YES! AWESOME! These code snippets, together, do appear to fix it! :-)
Just to be clear to readers of this thread... to fix this problem, this is the code I placed in my functions.php file in my theme as requested:
/**
* Restore Co-Authors Plus Plugin & Yoast SEO Sitemap Compatibility
*/
function cpt_guest_authors_sitemap( $post_types ) {
$post_types['guest-author'] = 'guest-author';
return $post_types;
}
add_filter( 'wpseo_accessible_post_types', 'cpt_guest_authors_sitemap' );
function myseo_sitemap_guest_author_url( $url, $author ) {
if ( is_object( $author ) && $author->post_type === 'guest-author' ) {
$user_nicename = preg_replace( '`^cap-`', '', $author->post_name );
$url = get_author_posts_url( $author->ID, $user_nicename );
}
return $url;
}
add_filter( 'wpseo_xml_sitemap_post_url', 'myseo_sitemap_guest_author_url', 10, 2 );
function myseo_remove_author_taxonomy( $type ) {
if ( $type === 'author' ) {
unregister_taxonomy( 'author' );
}
return $type;
}
add_filter( 'wpseo_build_sitemap_post_type', 'myseo_remove_author_taxonomy' );
I'll try to create PHP class for integration between Co Authors and Yoast SEO plugin based on these snippets. When I finish this, I'll submit PR to co-authors repo and I hope that will be fixed in next releases.
I'll try to create PHP class for integration between Co Authors and Yoast SEO plugin based on these snippets. When I finish this, I'll submit PR to co-authors repo and I hope that will be fixed in next releases.
It certainly is a huge improvement. There's only one issue left that I've experienced: If you go to the author sitemap, the links are all created with underscores in the names, which links to the author profile pages. However, they should be rewritten to send people to their associated "guest author" profile pages, if they are mapped, which all use hyphens instead of underscores, or the list of articles (if shown) on their profile page will be missing. Do you see that issue, or is that just with my site?
I don't have enabled guest authors on production servers. I've created a test website for this issue (with only couple authors). I didn't yet test mapping between WP users and guest authors. I'll try to investigate it.
It's possible that there are other issues (related to guest author page) because Co Authors plugin set is_author
to true if it's guest author page. I didn't yet test ability to set noindex
for some guest author or something like this.
It'll be helpful if you can send more details how to I reproduce your last issue (user_nicename
should contains -
instead of _
). Could you send couple screenshots?
Here are two screenshots. Only one real user is on the server other than the admin, to be mapped to its associated guest user:
In this example, both of the links to the profiles work, and both appear identical except for the hyphen and underscore difference, and the difference that the "real" profile page does not show the list of articles she wrote, while the "guest author" profile page does. If they are mapped together they show identical profiles except for the missing articles list in the one, while if the mapping is disconnected, the guest author shows the list of articles as it should and the main author profile page shows nothing but the "no articles are attributed to this author" notice.
I was able to reproduce your issue. I think that the easiest solution is removing "linked accounts" from author sitemap (there is method get all linked accounts
). I've rearranged the code:
/**
* Restore Co-Authors Plus Plugin & Yoast SEO Sitemap Compatibility.
*/
function myseo_accessible_post_types( $post_types ) {
$post_types['guest-author'] = 'guest-author';
return $post_types;
}
add_filter( 'wpseo_accessible_post_types', 'myseo_accessible_post_types' );
function myseo_check_sitemap_type( $type ) {
if ( $type === 'guest-author' ) {
add_filter( 'wpseo_xml_sitemap_post_url', 'myseo_sitemap_guest_author_url', 10, 2 );
} elseif ( $type === 'author' ) {
unregister_taxonomy( 'author' );
add_filter( 'wpseo_sitemap_entry', 'myseo_sitemap_author_excludes_linked_accounts', 10, 3);
}
return $type;
}
add_filter( 'wpseo_build_sitemap_post_type', 'myseo_check_sitemap_type' );
function myseo_sitemap_guest_author_url( $url, $guest_author ) {
if ( is_object( $guest_author ) ) {
$user_nicename = preg_replace( '#^cap\-#', '', $guest_author->post_name );
$url = get_author_posts_url( $guest_author->ID, $user_nicename );
}
return $url;
}
function myseo_sitemap_author_excludes_linked_accounts( $url, $type, $author ) {
static $linked_account_user_ids;
if ( ! isset( $linked_account_user_ids ) ) {
global $coauthors_plus;
$linked_account_user_ids = array();
if ( is_object( $coauthors_plus->guest_authors ) ) {
$linked_account_user_ids = wp_list_pluck(
$coauthors_plus->guest_authors->get_all_linked_accounts(),
'ID'
);
}
}
if ( ! empty( $linked_account_user_ids ) && is_object( $author ) &&
in_array( $author->ID, $linked_account_user_ids, true )
) {
return false;
}
return $url;
}
I was able to reproduce your issue. I think that the easiest solution is removing "linked accounts" from author sitemap (there is method
get all linked accounts
). I've rearranged the code:/** * Restore Co-Authors Plus Plugin & Yoast SEO Sitemap Compatibility. */ function myseo_accessible_post_types( $post_types ) { $post_types['guest-author'] = 'guest-author'; return $post_types; } add_filter( 'wpseo_accessible_post_types', 'myseo_accessible_post_types' ); function myseo_check_sitemap_type( $type ) { if ( $type === 'guest-author' ) { add_filter( 'wpseo_xml_sitemap_post_url', 'myseo_sitemap_guest_author_url', 10, 2 ); } elseif ( $type === 'author' ) { unregister_taxonomy( 'author' ); add_filter( 'wpseo_sitemap_entry', 'myseo_sitemap_author_excludes_linked_accounts', 10, 3); } return $type; } add_filter( 'wpseo_build_sitemap_post_type', 'myseo_check_sitemap_type' ); function myseo_sitemap_guest_author_url( $url, $guest_author ) { if ( is_object( $guest_author ) ) { $user_nicename = preg_replace( '#^cap\-#', '', $guest_author->post_name ); $url = get_author_posts_url( $guest_author->ID, $user_nicename ); } return $url; } function myseo_sitemap_author_excludes_linked_accounts( $url, $type, $author ) { static $linked_account_user_ids; if ( ! isset( $linked_account_user_ids ) ) { global $coauthors_plus; $linked_account_user_ids = array(); if ( is_object( $coauthors_plus->guest_authors ) ) { $linked_account_user_ids = wp_list_pluck( $coauthors_plus->guest_authors->get_all_linked_accounts(), 'ID' ); } } if ( ! empty( $linked_account_user_ids ) && is_object( $author ) && in_array( $author->ID, $linked_account_user_ids, true ) ) { return false; } return $url; }
Tried this code, but I actually can't use it because I can't map the accounts without losing the list of posts on their profiles. It does remove the mapped authors from the sitemap, however. Also if only mapped authors are in the sitemap, it lists the sitemap but clicking on it gives a 404 not found.
Hi and time to ressurrect this issue. Was able to fix the sitemap with the snippets here yet still having "noindex" is a much worse problem. Any idea how to solve noindex?
I was able to get mine to work by including this in my functions.php file:
` /**
function myseo_sitemap_guest_author_url( $url, $author ) {
if ( is_object( $author ) && $author->post_type === 'guest-author' ) {
$user_nicename = preg_replace( '^cap-
', '', $author->post_name );
$url = get_author_posts_url( $author->ID, $user_nicename );
}
return $url;
}
add_filter( 'wpseo_xml_sitemap_post_url', 'myseo_sitemap_guest_author_url', 10, 2 );
function myseo_remove_author_taxonomy( $type ) { if ( $type === 'author' ) { unregister_taxonomy( 'author' ); } return $type; } add_filter( 'wpseo_build_sitemap_post_type', 'myseo_remove_author_taxonomy' ); `
I was having trouble resolving the noindex,follow
issue on guest author archives with the suggested code snippets and had luck with the following:
add_filter( 'wpseo_robots', 'fix_guest_author_noindex', 10, 2 );
/**
* CoAuthors Plus and Yoast are incompatible where the author archives for guest authors are output as noindex.
* This filter will determine if we're on an author archive and reset the robots.txt string properly
*/
function fix_guest_author_noindex( $robots_string, $obj ) {
$post_type = get_post_type( get_queried_object_id() );
// If this is a guest author archive and hasn't manually been set to noindex, make sure the robots.txt string is set properly
if ( 'guest-author' === $post_type &&
is_a( $obj, 'Yoast\WP\SEO\Presentations\Indexable_Author_Archive_Presentation' ) &&
isset( $obj->model->is_robots_noindex ) && ( empty( $obj->model->is_robots_noindex ) || 0 === intval( $obj->model->is_robots_noindex ) ) ) {
$robots_string = 'index, follow';
}
return $robots_string;
}
Please inform the customer of conversation # 668286 when this conversation has been closed.
I am experiencing the issue with noindex being set on guest authors since upgrading past version 14 and I would like to address it by writing a class that extends Indexable_Presentation
to use in place of Indexable_Author_Archive_Presentation
for guest authors.
Is that possible?
To expand a bit on @bengreeley 's solution above, using the wpseo_robots_array
allows other filters to still add values to the robots tag:
// Make CoAuthor archive indexable.
add_filter( 'wpseo_robots_array', 'allow_indexing_guest_author_archive', 10, 2 );
/**
* Make CoAuthor archive indexable.
*
* CoAuthors Plus and Yoast are incompatible where the author archives for guest authors are output as noindex.
* This filter will determine if we're on an author archive and reset the robots.txt string properly.
*
* @param string $robots The meta robots directives to be echoed.
* @param Indexable_Presentation $presentation The presentation of an indexable.
*/
function allow_indexing_guest_author_archive( $robots, $presentation ) {
if ( ! is_author() ) {
return $robots;
}
if ( ! is_a( $presentation, '\Yoast\WP\SEO\Presentations\Indexable_Author_Archive_Presentation' ) ) {
return $robots;
}
if ( ! isset( $presentation->model->is_robots_noindex ) ) {
return $robots;
}
/*
* If this is a guest author archive and hasn't manually been set to noindex,
* make sure the robots.txt string is set properly.
*/
if ( empty( $presentation->model->is_robots_noindex ) || 0 === intval( $presentation->model->is_robots_noindex ) ) {
if ( ! is_array( $robots ) ) {
$robots = array();
}
$robots['index'] = 'index';
$robots['follow'] = 'follow';
}
return $robots;
}
@barryceelen 's solution wasn't working for me (not seeing a is_robots_noindex
property) on the latest version of Yoast SEO (20.3
). This solution worked for me.
/**
* Make CoAuthor archive indexable.
*
* CoAuthors Plus and Yoast are incompatible where the author archives for guest authors are output as noindex.
* This filter will determine if we're on an author archive and reset the robots.txt string properly.
*
* @param string $robots The meta robots directives to be echoed.
* @param Indexable_Presentation $presentation The presentation of an indexable.
*/
function allow_indexing_guest_author_archive( $robots, $presentation ) {
if ( ! is_author() || ! is_a( $presentation, '\Yoast\WP\SEO\Presentations\Indexable_Author_Archive_Presentation' ) ) {
return $robots;
}
// Get the post meta properties for the Guest Author, incase it was manually set.
$id = (int) get_queried_object_id();
$noindex = (int) get_post_meta( $id, '_yoast_wpseo_meta-robots-noindex', true );
$nofollow = (int) get_post_meta( $id, '_yoast_wpseo_meta-robots-nofollow', true );
if ( ! is_array( $robots ) ) {
$robots = array();
}
$robots['index'] = $noindex ? 'noindex' : 'index';
$robots['follow'] = $nofollow ? 'nofollow' : 'follow';
return $robots;
}
Please give us a description of what happened.
When using Yoast SEO 7.0.1 the sitemap created for the Co-Authors Plus "guest-authors" taxonomy gives incorrect URL locations, resulting in 404 Not Found pages listed in the sitemap. If the taxonomy is excluded from the sitemap, a meta robots tag telling search engines to "noindex" the working pages is added. See this URL as an example: https://portofdewatto.com/author/leanna-krotzer/
Please describe what you expected to happen and why.
The sitemap for Co-Authors Plus "guest-authors" taxonomy pages should be correctly listed in the sitemap. OR, the ability to exclude that taxonomy from the sitemap should NOT ALSO add "noindex" meta tags to perfectly functioning pages.
How can we reproduce this behavior?
Technical info