admin管理员组

文章数量:1125102

After switching to a different wordpress theme, Google started adding a sitename to ALL page titles in the search results.

E.g.:

"Page title - Sitename"

Even when leaving the sitename area blank, Google still adds the homepage title next to every single page. This only started hapening after I switched to my new current wordpress theme.

I am using the Yoast SEO Plugin and even tried removing "%%sep%% %%sitename%%" in the settings, but still doesn't work.

I contacted the theme developer, this was his response:

"The theme doesn't set any custom title. It uses default add_theme_support( 'title-tag' ); wordpress function and Seo by Yoast works with this."

How can I remove the sitename? Do I need to change the header.php code? If not which code should I edit?

After switching to a different wordpress theme, Google started adding a sitename to ALL page titles in the search results.

E.g.:

"Page title - Sitename"

Even when leaving the sitename area blank, Google still adds the homepage title next to every single page. This only started hapening after I switched to my new current wordpress theme.

I am using the Yoast SEO Plugin and even tried removing "%%sep%% %%sitename%%" in the settings, but still doesn't work.

I contacted the theme developer, this was his response:

"The theme doesn't set any custom title. It uses default add_theme_support( 'title-tag' ); wordpress function and Seo by Yoast works with this."

How can I remove the sitename? Do I need to change the header.php code? If not which code should I edit?

Share Improve this question edited Oct 22, 2018 at 6:42 Uwe Keim 17711 bronze badges asked Apr 11, 2016 at 10:32 johnjohn 411 silver badge2 bronze badges 1
  • Can you post a link to the current site, or copy and paste a snippet from the header.php showing <title>so that we can see more information? – Monkey Puzzle Commented Apr 11, 2016 at 12:36
Add a comment  | 

2 Answers 2

Reset to default 7

By default WordPress use _wp_render_title_tag to hook wp_head ( see here )

add_action( 'wp_head', '_wp_render_title_tag', 1 );

This function is wrapper of wp_get_document_title to show title tag on theme if add_theme_support( 'title-tag' ); added in theme file functions.php ( commonly ). https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-includes/general-template.php#L944

If you see filter document_title_parts on function wp_get_document_title(), we can filter parameters that used in title ( title, page, tagline, site ).

Let say if we need to remove site name title part of homepage and single post, you just need to unset parameter title and site with conditional tags, here the sample code ( add in functions.php theme file ):

add_filter( 'document_title_parts', function( $title )
{
    if ( is_home() || is_front_page() )
        unset( $title['title'] ); /** Remove title name */

    if ( is_single() )
        unset( $title['site'] ); /** Remove site name */

    return $title;

}, 10, 1 );

About your issue in Google indexing, it's off-topic here.

In your header.php you may need to replace:

<title><?php whatever code you find in your existing theme ?></title>

with:

<title><?php wp_title(''); ?></title>

Make sure you make a copy first so you can revert back if you need to!

本文标签: customizationHow can I remove the sitename or homepage title from all page titles