Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yoast SEO 7.0.1 Co-Authors Plus Plugin Incompatibility #9147

Open
2 tasks done
gregarios opened this issue Mar 7, 2018 · 24 comments · Fixed by Automattic/Co-Authors-Plus#912
Open
2 tasks done

Yoast SEO 7.0.1 Co-Authors Plus Plugin Incompatibility #9147

gregarios opened this issue Mar 7, 2018 · 24 comments · Fixed by Automattic/Co-Authors-Plus#912

Comments

@gregarios
Copy link

gregarios commented Mar 7, 2018

  • I've read and understood the contribution guidelines.
  • I've searched for any related issues and avoided creating a duplicate issue.

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?

  1. Install Co-Authors Plus plugin
  2. create a guest-author and a post with guest author.
  3. go to the sitemap and try to use one of the URLs for the "guest-authors" listed in the sitemap
  4. go to the real guest author (bio) page and see the noindex meta addded to the source code of the page (with no ability to remove it since Yoast SEO 7)

Technical info

  • WordPress version: 4.9.4
  • Yoast SEO version: 7.01
  • Relevant plugins in case of a bug: Co-Authors Plus
@moorscode moorscode changed the title Yoast SEO 7.01 Co-Authors Plus Plugin Incompatibility Yoast SEO 7.0.1 Co-Authors Plus Plugin Incompatibility Mar 8, 2018
@jakebellacera
Copy link

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.

screen shot 2018-03-19 at 7 44 22 am

@benvaassen
Copy link
Contributor

benvaassen commented Mar 21, 2018

Thank you for reporting this bug.
I've assigned someone to further investigate the issue to check if we are able to solve this.

@jdevalk
Copy link
Contributor

jdevalk commented Mar 21, 2018

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

@danielbachhuber
Copy link
Contributor

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

@kmcaloon
Copy link

kmcaloon commented Jan 7, 2019

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.

@gregarios
Copy link
Author

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.

@stodorovic
Copy link
Contributor

@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
Copy link
Author

gregarios commented Jan 18, 2019

@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:

screen shot 2019-01-18 at 7 27 54 am

All the links in the website are in the normal format:
https://wshv.net/author/author-name/

@stodorovic
Copy link
Contributor

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.

@gregarios
Copy link
Author

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! :-)
screen shot 2019-01-18 at 11 21 05 am

@gregarios
Copy link
Author

gregarios commented Jan 18, 2019

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' );  

@stodorovic
Copy link
Contributor

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.

@gregarios
Copy link
Author

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?

@stodorovic
Copy link
Contributor

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?

@gregarios
Copy link
Author

gregarios commented Jan 18, 2019

Here are two screenshots. Only one real user is on the server other than the admin, to be mapped to its associated guest user:

screen-shot-2019-01-18-at-1 06 21-pm

screen-shot-2019-01-18-at-1 06 47-pm

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.

@stodorovic
Copy link
Contributor

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;
}

@gregarios
Copy link
Author

gregarios commented Jan 22, 2019

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.

@heArt-coder
Copy link

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?

@gregarios
Copy link
Author

gregarios commented Aug 18, 2020

I was able to get mine to work by including this in my functions.php file:

`
/**

  • 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' );
`

@bengreeley
Copy link

bengreeley commented Nov 11, 2020

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;
}

@josh-yoast
Copy link

Please inform the customer of conversation # 668286 when this conversation has been closed.

@douglas-johnson
Copy link

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?

@barryceelen
Copy link

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;
}

rebeccahum pushed a commit to Automattic/Co-Authors-Plus that referenced this issue Jan 16, 2023
* fix(yoast): prevent no-indexing of guest authors' archive pages

Closes Yoast/wordpress-seo#9147
Closes Automattic/newspack-plugin#1506

* Fixes the og:url attribute for gues author archive

Co-authored-by: Leo Germani <[email protected]>
@timbolimboslice
Copy link

timbolimboslice commented Mar 15, 2023

@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 );
	$ = (int) get_post_meta( $id, '_yoast_wpseo_meta-robots-', true );

	if ( ! is_array( $robots ) ) {
		$robots = array();
	}

	$robots['index']  = $noindex ? 'noindex' : 'index';
	$robots['follow'] = $ ? '' : 'follow';

	return $robots;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.