My website theme header.php uses this code:

<title><?php wp_title('&lsaquo;', true, 'right'); ?></title>

And I'm seeing two <title> tags in the page source.

How can I solve this?


You are getting the two <title> tags most likely because your theme has the title-tag support which automatically adds the title tags in the document head.

Excerpt from the above linked page on Make WordPress Core:

Adding titles to themes

Starting with 4.1 and Twenty Fifteen, the recommended way for themes to display titles is by adding theme support like this:

function theme_slug_setup() {
  add_theme_support( 'title-tag' );
add_action( 'after_setup_theme', 'theme_slug_setup' );

Support should be added on the after_setup_theme or init action, but no later than that. It does not accept any further arguments.

By declaring support like this, themes acknowledge that they are not defining titles on their own and WordPress can add it safely without duplication.

So if the theme does support the automatic <title> tag (try looking for add_theme_support( 'title-tag' ) in the theme's functions.php file), then don't manually put the title tags in the header.php template.

And if you actually wanted to customize the title or the positioning of the title parts, then you can use the document_title_parts hook or if you're using any SEO plugin, then you might be able to adjust the title parts without using any custom code; however, please consult the plugin support documentation/site/forums for assistance in adjusting that parts or customizing the site title. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.