Home » Wordpress » WordPress Double Title In header – No seo plugins

WordPress Double Title In header – No seo plugins

Posted by: admin February 26, 2018 Leave a comment

Questions:

Working on a site for a client: http://tinyurl.com/lc4ewwf

I did not create this template, and my client wants me to remover the double titles that is happening to the sub pages. The thing is, I can not figure out what is causing this to happen. This is not happening on the main page either. There is no SEO scripts installed either.

This is what the header.php looks like

<?php
/**
 * The Header for our theme.
 *
 * Displays all of the <head> section and everything up till <div id="main">
 *
 * @package WordPress
 * @subpackage Twenty_Ten
 * @since Twenty Ten 1.0
 */
?><!DOCTYPE html>
<html <?php language_attributes(); ?>>
<head>
<meta charset="<?php bloginfo( 'charset' ); ?>" />
<title><?php
    /*
     * Print the <title> tag based on what is being viewed.
     */
    global $page, $paged;

    wp_title( '|', true, 'right' );

    // Add the blog name.
    bloginfo( 'name' );

    // Add the blog description for the home/front page.
    $site_description = get_bloginfo( 'description', 'display' );
    if ( $site_description && ( is_home() || is_front_page() ) )
        echo " | $site_description";

    // Add a page number if necessary:
    if ( $paged >= 2 || $page >= 2 )
        echo ' | ' . sprintf( __( 'Page %s', 'twentyten' ), max( $paged, $page ) );

    ?><?php echo get_the_title($ID); ?></title>
<link rel="profile" href="http://gmpg.org/xfn/11" />
<?php /*?><link rel="stylesheet" type="text/css" media="all" href="<?php bloginfo( 'stylesheet_url' ); ?>" /><?php */?>
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
<?php
    /* We add some JavaScript to pages with the comment form
     * to support sites with threaded comments (when in use).
     */
    if ( is_singular() && get_option( 'thread_comments' ) )
        wp_enqueue_script( 'comment-reply' );

    /* Always have wp_head() just before the closing </head>
     * tag of your theme, or you will break many plugins, which
     * generally use this hook to add elements to <head> such
     * as styles, scripts, and meta tags.
     */
    wp_head();
    ?>
    <!-- Styles -->
<link href="<?php bloginfo('template_url'); ?>/css/bootstrap.css" rel="stylesheet">
<link href="<?php bloginfo('template_url'); ?>/css/bootstrap-responsive.css" rel="stylesheet">
<link href="<?php bloginfo('template_url'); ?>/css/styles.css" rel="stylesheet">
<link href="<?php bloginfo('template_url'); ?>/css/wordpress.css" rel="stylesheet">

<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
      <script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->

<!-- Favorite Icons -->
<link rel="shortcut icon" href="<?php bloginfo('template_url'); ?>/images/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="<?php bloginfo('template_url'); ?>/images/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="<?php bloginfo('template_url'); ?>/images/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="<?php bloginfo('template_url'); ?>/images/apple-touch-icon-57-precomposed.png">

<!-- TypeKit -->
<script type="text/javascript" src="http://use.typekit.com/zlf3uad.js"></script>
<script type="text/javascript">try{Typekit.load();}catch(e){}</script>
<!-- For slideshow -->
</head>

<body>

Am I just crazy and is overlooking something?

Answers:
wp_title( '|', true, 'right' );

and

echo get_the_title($ID);

outputs the title; therefore you have two titles.


Try hooking this up into wp_title function via functions.php:

function my_wp_title( $title, $sep ) {
    global $paged, $page;

    if ( is_feed() ) {
        return $title;
    }

    // Add the site name.
    $title .= get_bloginfo( 'name', 'display' );

    // Add the site description for the home/front page.
    $site_description = get_bloginfo( 'description', 'display' );
    if ( $site_description && ( is_home() || is_front_page() ) ) {
        $title = "$title $sep $site_description";
    }

    // Add a page number if necessary.
    if ( $paged >= 2 || $page >= 2 ) {
        $title = "$title $sep " . sprintf( __( 'Page %s', 'textdomain' ), max( $paged, $page ) );
    }

    return $title;
}
add_filter( 'wp_title', 'my_wp_title', 10, 2 );

and use the function in the title:

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

Questions:
Answers:

You’ve got two calls that look like they’re duplicated. Inside the PHP block in the <title> tag, you’re calling:

wp_title( '|', true, 'right' );

Accord to the documentation, this will return the title of the post.

Then, after your PHP block, you’re calling:

echo get_the_title($ID)

Which does exactly the same thing.