INN / umbrella-citylimits

CityLimits.org Site
https://citylimits.org
GNU General Public License v2.0
0 stars 2 forks source link

Research tab title issue for guest author pages #134

Closed MirandaEcho closed 4 years ago

MirandaEcho commented 4 years ago

Jarett's name appears in the tab title for any guest author he created. We need to determine if this is something that's happening in Largo, or elsewhere. It may be able to be updated with Yoast or it may be a plugin issue/configuration (Co-authors perhaps?)

joshdarby commented 4 years ago

This looks like an issue with how Yoast is configured.

Here's the configuration setting for the SEO title for author archives: %%name%%, Author at %%sitename%% %%page%%

So since Jarrett created this Guest Author (a custom post type), it makes sense that this is pulling in his name as the Author 🤔

joshdarby commented 4 years ago

This can probably be fixed by using the wpseo_title filter and writing a function that swaps out the current author display name for the real author display name if they don't match. Something like this would work:

function yoast_filter_author_page_title( $title ) {

    if ( ! is_author() ) {
        return $title;
    }

    // current name that's displaying
    $current_display_name = get_the_author_meta( 'display_name', get_query_var( 'author' ) );

    // object for the real author
    $author_obj = get_queried_object();

    // new display name to swap in for the real author
    $new_display_name = $author_obj->display_name;

    if( $current_display_name != $new_display_name ){
        return str_replace( $current_display_name, $new_display_name, $title );
    } else {
        return $title;
    }

}
add_filter( 'wpseo_title', 'yoast_filter_author_page_title' );