I have a loop on my index page. The problem I'm having is that the HTML generated has a different title from what I wrote in the template part header.php in <head>

I do know for sure it takes as new value in <title> for the current title of my last post (which is seen in my loop). If I had to guess, I'd say there's something generating thid from each article in the loop that can rewrite the <title> in the <head>, but I can't find out what.


Here is my loop, to be more precise, it's actually the value in <h3><?php the_title()?></h3> which is put in the <head><title></title></head>

<?php if ( is_home() ) {   query_posts( 'cat=-5' );   } ?>
<?php if (have_posts()) : ?>
  <?php while (have_posts()) : the_post(); ?>
    <div <?php post_class()?>>
      <h3 class="post-title">
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
      <p class="post-info">
        Posté le <?php the_date(); ?> dans <?php the_category(', '); ?> par <?php the_author(); ?>.<br />
        <?php the_tags(); ?>
      <div class="post-excerpt">
        <?php the_excerpt(); ?>
  <?php endwhile; ?>
<?php else : ?>
  <p class="nothing">
    Il n'y a pas de Post à afficher !
<?php endif; ?>
<?php wp_reset_query(); ?>

And this is my <head> :

<head <?php language_attributes(); ?>>
    <meta charset="<?php bloginfo('charset'); ?>">
    <title><?php the_title(); ?></title>
    <link rel="stylesheet" type="text/css" href="http://necolas.github.io/normalize.css/3.0.1/normalize.css">
    <link rel="stylesheet" href="<?php echo get_template_directory_uri();?>/css/app.css" type="text/css">
    <link rel= "icon" href="<?php echo get_template_directory_uri();?>/favicon.ico" type="image/x-icon " />
    <link href='http://fonts.googleapis.com/css?family=Gloria+Hallelujah' rel='stylesheet' type='text/css'>
    <?php wp_head(); ?>
  • 2
    Please add relevant code like the loop and your header.
    – kraftner
    May 26, 2014 at 9:52
  • It might be down to some filter that one of your extensions do. Reset everything (like Theme and Plugins) and enable them one by one until the problem occurs again. The last activated theme / plugin is the one that does that.
    – LeMike
    May 26, 2014 at 10:21
  • @kraftner here is the code :) May 26, 2014 at 10:38
  • Although this might not clear your problem, but you should really not be using query_posts. You should be using WP_Query May 26, 2014 at 10:50

1 Answer 1


To start this off, you should not be using query_posts for custom queries. Directly from the codex

Note: This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new instance of the query. It is inefficient (re-runs SQL queries) and will outright fail in some circumstances (especially often when dealing with posts pagination).

You should be using WP_Query. You should also have a read here

Ok, now to the actual problem. You have the_title() and wp_title() mixed up here. the_title() displays the post title in posts, and should be in the loop. wp_title() retrieves page title, and should be used in the header. Again I quote from the codex

This function, and not a work-around, is required for publicly by WordPress standards.

So you need to change

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


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

in your header

  • Thanks ! At least my title problem was just a simple thing ... I still have problems to see this kind of difference, the_title seemed good for me. About the problem of WP_Query, I did tried the best to use WP_Query, but I'm not native english speaker, and some of PHP are kinda blurry to me... both together are sometimes hard to play with. So I chose a solution which simply works... Even if it's not the best. I got a WP_Query in a second loop later on the page. Maybe that's an other problem. May 26, 2014 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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