Home > ramiro's blog > Avoiding Duplicate Title Tags on Pager Pages in Drupal

Avoiding Duplicate Title Tags on Pager Pages in Drupal

Google Webmaster Tools includes a tool called content analysis that you find in the Diagnostics section. The content analysis tool reported a suboptimal number of duplicate title tags and meta descriptions for some Drupal sites that I monitor with these tools.

Getting rid of duplicate title tags and meta descriptions caused by the pager is actually quite simple. When using the Meta Tags module with the setting ALL=INDEX,FOLLOW for Default robots meta tag: you can adjust the robots Meta tag in your theme, so that pages that contain the page parameter in the URL are not indexed using the following code snippet in the head section of your page.tpl.php template file.

<?php
if (isset($_GET['page'])) {
   
$head = str_replace('<meta name="robots" content="index,follow" />',
   
'<meta name="robots" content="noindex,follow" />', $head);
}
print
$head;
?>

If you do not use the Meta tags module or another solution to add Meta tags to the head section of your HTML, the robots Meta tag is not contained in your page source. In this case you can simply append this tag to your head variable like that.

<?php
if (isset($_GET['page'])) {
 
$head .= '<meta name="robots" content="noindex,follow" />';
}
print
$head;
?>

Setting the robots Meta tag to noindex,follow tells search engine crawlers that care about the robots Meta tag and the robots exclusion standard to not index these pages, i.e. they won't appear in search engine results but linked pages will be crawled, provided they are not linked with rel="nofollow".

Adding this code to your theme is a quick hack and not the optimal solution, because it is not easily reusable. Since I want to get rid of this in my theme sometime in the future, I added a feature request to the Meta tags module with a patch that resolves issues with duplicate title tags and meta descriptions on pages generated by Drupal's pager.

The fact that Google displays such issues in the diagnostics section of their webmaster tools indicates that they play a role in evaluating the quality of your site. It is not likely that your site will be considered spam and get banned because of these issues, but it is certainly better to get rid of them.

If your paged results are built using a view, you can add "Page n" to the page titles with this PHP code in the view header:

<?php
  $page = isset($_GET['page']) ? $_GET['page']+1 : '1';
  drupal_set_title(drupal_get_title().t(' - Page ').$page);
?>


It's certainly helped our content analysis report, although I only made the change two days ago, so it's a bit soon to assess the impact on our page rankings.

This way the titles are not identical but still very similar. I prefer to not have pages generated by the pager in search engine indexes, since they are usually not attractive on SERPs and also not as landing pages for the users. Users then have to find the content they are looking for on your site, which is often considered reason enough to leave your site immediately.

The solution suggested can be adopted, even if to change the META tag content, and not to change the page title; after all, most of the pages which have the duplicated title problem are views.
I think that to change the template files used by a theme is not the solution; at every update of the theme, its template files should be changed.

As the problem arises also with pages generated by Drupal core modules (in my case, user, user/password, and user/register has all the same title) the problem can be resolved by creating a module like the All in One SEO Pack for Wordpress.

Fixing such issues in a module is a better solution as I also pointed out in the article. The problem with updates will arise if you use a core or contributed themes, but not if you created the theme yourself.

I tried it with Views version 6.x-2.0-rc1, but even after cleaning its cache, the title didn't change.

Do you use Ajax views? If so, turn off JavaScript in your browser and see what happens.

<?php $page = isset($_GET['page']) ? $_GET['page']+1 : '1'; drupal_set_title(drupal_get_title().t(' - Page ').$page); ?>

I have added that code to my page.tpl.php but nothing change to my title. Is there something wrong? Or where is the place should I placed the code?

Sorry For My bad Grammar
Thanks
It happens also when the page contains a table which is sortable. In that case, the code should also check for sort, and order. I don't understand why, anyway, Webmaster Tools is not able to understand that ‎/tracker?order=last_comment_timestamp&sort=asc‎, and ‎‎/tracker?order=type&sort=asc&page=1‎ are the same page. At least it should not consider what follows the question mark, and avoid to give such a misleading message.
This is now built into the Blueprint http://drupal.org/project/blueprint theme per this commit: http://drupal.org/cvs?commit=136425 Added in support for sorting tables too.

That's great news, thanks!

Had the same problem and the snippet did the trick. Thanks for the tip! I agree that indexing pages 2+ does not make much sense. According to the current stats for my sites those 2+ doing a great job working as exit pages. And btw, that blueprint module is not available for Drupal 6.
I just found out that I had the same problem with duplicate title tags. Your code snippets helped to solve the problem. THANKS!
I was wondering if there was a way to have the Title field in drupal not be shown on the page content but still be used in the Title tag.....

Yes, if you really don't want the title in content, modify the template files that output the title. In Drupal this usually happens in page.tpl.php and node.tpl.php.

Hi Guys,
I have the same problem but with the translated pages in my drupal site, the google webmaster tool tell me that I have got 4 identical pages for every translated page I made.
For example:
I create a page
www.example.com/node/1
then i translate it to
www.example.com/es/node/2
The webmaster tool count the page 2 as four different but identical pages leading to an error.
.../fr/node/2
.../node/2
.../de/node/2
Do you have any idea how can i solve it?
Thanks

Is the content translated to 4 languages?

Yes, it is.Why?

The best would be to redirect fr/node/2 to the French version and so on. I don't know whether there is a module that does this for you. Maybe the Global Redirect module (http://drupal.org/project/globalredirect), but that is a guess.

The best way to add the page number inside the page title is to use the snippet published by Mark by adding this code a the end of widthin your page template: <?php $page = isset($_GET['page']) ? $_GET['page']+1 : '1'; print 'Page '.$page; ?>