-
Notifications
You must be signed in to change notification settings - Fork 209
Description
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()
Co-Authors-Plus/php/integrations/yoast.php
Line 342 in d1b5b65
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.