I’m building a child theme and it currently has a very simple <head> section in header.php:

<head>
  <meta charset="<?php bloginfo( 'charset' ); ?>">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <title><?php wp_title( '|', true, 'right' ); ?></title>
  <link rel="profile" href="http://gmpg.org/xfn/11">
  <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
  <!--[if lt IE 9]>
  <script type="text/javascript" src="<?php echo get_template_directory_uri(); ?>/js/html5shiv.min.js"></script>
  <![endif]-->

  <?php wp_head(); ?>
</head>

I’m guessing wp_head() is responsible for the second <title> element (it appears just there in the final HTML), but other things I’ve read say this is impossible.

Should I be removing the <title> from my header.php, or should I be adding something to my functions to remove the title from wp_head() (eg. remove_action('wp_head', 'title') ?

Or should I be doing something else altogether?

2 s
2

The two title tags can be explained as that you are using a theme that is written for WordPress4.1 and actually is using 4.1. As from 4.1 you don’t need to call wp_title() in the head any more, you can make use of new title_tag theme support tag which automatically adds the wp_title() tag in the header

The parent theme you are using are most probably already doing this. Look in your functions.php for this line of code

add_theme_support( 'title-tag' );

As a solution, copy the parent theme header.php to your child theme and simply remove the wp_title() function from the child theme header.php

Here is also a great function to keep in mind for backwards compatibility and is useful for parent theme developers: (Taken from the codex)

 if ( ! function_exists( '_wp_render_title_tag' ) ) {
    function theme_slug_render_title() 
    {
        ?>
        <title>
            <?php wp_title( '|', true, 'right' ); ?>
        </title>
        <?php
    }
    add_action( 'wp_head', 'theme_slug_render_title' );
}

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *