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

CAP causing Yoast to render the wrong titles for author archives #1092

Open
justinmaurerdotdev opened this issue Jan 29, 2025 · 0 comments · May be fixed by #1093
Open

CAP causing Yoast to render the wrong titles for author archives #1092

justinmaurerdotdev opened this issue Jan 29, 2025 · 0 comments · May be fixed by #1093

Comments

@justinmaurerdotdev
Copy link

Hi, I've discovered an issue with the way CAP is handling its Yoast integration with respect to titles.

CAP uses this filter, wpseo_replacements, to fix Yoast's usage of the %%name%% placeholder. However, this filter is also during the rendering of the page <title>. This means that when the page is an author archive, the author's name is being substituted with the display names of all of the authors of the top post on the page.

It turns out that in this case, the $args->ID found in the filter_author_name_variable() method (and passed to get_coauthors()) is just defaulting to the first post in the loop, because that's what is set in $GLOBALS['post'] (the default when get_the_ID() is called with no arguments). This issue seems totally fixed by the addition of is_single() in the logic for whether to do the replacement.

I am assuming that this filter is intended to fix the author name strings for the schema/meta on individual posts (things that actually have co-authors), and that this fix won't impact anything negatively, but please chime in if you can think of some reason why this filter would be needed on an archive.

Here's an archived example of how that looks on our site: https://web.archive.org/web/20250122074639/https://reason.com/people/justin-zuckerman/

add_filter( 'wpseo_replacements' ...

add_filter( 'wpseo_replacements', [ __CLASS__, 'filter_author_name_variable' ], 10, 2 );

filter_author_name_variable()

if ( isset( $replacements['%%name%%'], $args->ID ) ) {

Title_Presenter->get_title()
https://github.com/Yoast/wordpress-seo/blob/fedc1b286bb15dc44c2150ae129cd3beba01321d/src/presenters/title-presenter.php#L67

I'll submit a PR shortly with my fix (literally just && is_single()) on line 342.

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