How to change title of...

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
TonW's picture

Hi,

I have been checking Google Webmaster Tools and i got 32 Duplicate meta descriptions:

All the /node?page=* pages.

How do i add custom titles for those pagination pages?

Thanks.

Comments

Ah...

NikLP's picture

I was going to leave an answer here, but I thought about it, and I would have been wrong.

So, subscribing... :)

Kineta Systems - Web Development in Nottingham, UK

This isn't the answer your looking for

Brian.Harris's picture

I personally add rel="nofollow" to my pagination menu in order to prevent duplicate content. I'm curious to see the true solution.

Nofollow doesn't prevent

Z2222's picture

Nofollow doesn't prevent spiders from indexing those pages if there are other ways they can find the pages. If you do block the paginated pages there should be another way for search engine spiders to reach your older content. Otherwise, once a post goes to ?page=2 there won't be any internal links pointing to it.

I don't know about adding meta description to the paginated pages, but I block the home page's pagination with robots.txt:

User-agent: *
Disallow: /node

Otherwise you get the following duplicated page:

example.com/node (when you are on /node?page=1 the #1 links to /node)

Wont work for me.

TonW's picture

I dont think that would work for me, i am using the classic clean urls, node/1 and all those, disallowing /node would disallow all my content, not only the pagination.

Or am i wrong?

Google and Yahoo

Z2222's picture

The following should work in Google and Yahoo:

# blocks only /node
Disallow: /node$

# blocks any URLs that contain the parameter page=
Disallow: /*page=

I wouldn't use the last rule though (blocking pagination) because Google will probably have trouble finding older posts.

Still looking.

TonW's picture

Still looking for a way to rename those pagination pages.

Aha!

NikLP's picture

Ok I misunderstood what you're trying to do - if I understand correctly, you have many paginated pages from a single view/taxonomy list that all have similar meta descriptions?

The way to override this is use the nodewords (meta tags) module - in the settings, you can opt to suppress meta tags for all listed pages - it will only display the meta tags on the original (first) page.

Kineta Systems - Web Development in Nottingham, UK

Both

TonW's picture

The idea is adding differente title and metatags for all the pagination pages /node?page=1.

pagination

Z2222's picture

I don't know how to do it but there might be some ideas in the code from the page_title module...

These are two things Drupal needs:

  • different titles on paginated pages (even just <title>Page 2 - [title]</title> would be enough)
  • clean URLs for pagination

Exactly

Duplika's picture

That's exactly what I need. On a default front page, I have hundreds of "?page=10, ?page=11, etc." duplicate meta descriptions and duplicate title tags. Both set of errors are reported at the Google Webmaster Tools and I can't find a way to avoid them.

Blocking the pagination pages from Google is not a good approach since, like J. Cohen says, what we need is:

  • Different titles like "Title - Page 2" for example
  • Different meta description or no description at all for the pagination pages

Does anyone have any clue on how to accomplish this?

Drupal Soul - Drupal Services

Already asked a feature for

TonW's picture

Already asked a feature for Page Title module in this feature request: http://drupal.org/node/224262 but i dont know how to answer what nicholasThompson asks.

True

TonW's picture

I have to agree with you in that, both things would be real good, and there is a "bug" too in the pagination, first page is linking to /node not to the url and it looks duplicate for the search engines.

/node bug

Z2222's picture

It's definitely a duplicate to the front page, but I'm wondering if it's a bug?

If you have a custom front page then /node is a link to the first set of posts in the paginated series.

I think it would be better to just make this standard practice:

  • always create a custom front page. If you have a custom front page then /node is not duplicate...
  • always use URL aliases and the Global Redirect module to redirect from /node/123 URLs to the URL aliases

Uh...?

NikLP's picture

Surely if you have a custom home page, then /node is always a duplicate?!

Either way, you can get around that using robots.txt.

I'll have a word with the maintainer of page_title about the pagination option. How serious is this issue tho? This is the first time I've heard mention of it.

Kineta Systems - Web Development in Nottingham, UK

front page

Z2222's picture

The default setting of Drupal is that the home page is a duplicate of /node. If you make a custom front page then /node is no longer duplicate content.

Interesting points!

nicholasThompson's picture

That new Content Analysis is REALLY nifty!

If you install Global Redirect (as long as you're not using i18n as they dont like each other right now!) then the issue of dupe content between the frontpage path and the actual frontpage (eg, http://example.com/ and http://example.com/node) is solved as Global Redirect does a 301 redirect there. It also solves the issue of aliases and source paths providing the same content.

Interesting suggestion about Page Title's having an appended "Page 2/3/4/5" feature for listings/views... I'm currently working on integrating Page Title 2 (currently in alpha stages) with Views.
http://drupal.org/node/176985

Page Title suffixing should be pretty easy... All you'd need to do is check if there is a "page" argument and then suffix the data. Thinking about it though... What if you have a page with multiple pagers on it? What should happen to the title then? (this is a bit of an "edge case")

If you install Global

Z2222's picture

If you install Global Redirect (as long as you're not using i18n as they dont like each other right now!) then the issue of dupe content between the frontpage path and the actual frontpage (eg, http://example.com/ and http://example.com/node) is solved as Global Redirect does a 301 redirect there.

Good point... I didn't notice that on my sites because I generally use a custom front page. Global Redirect redirects whatever you set your home page URL to be to the actual home page (e.g., node or front_page.

What if you have a page with multiple pagers on it? What should happen to the title then? (this is a bit of an "edge case")

What do you mean by multiple pagers?

Hm...

NikLP's picture

Not sure how that would work, but as you say Nick, multiple pagers is pretty damn niche. I can't even think of a use case at the moment. I mean, this would never work with Panels (or something) and pagers, would it?

I was thinking maybe we could have a token for pagers, but I suppose it's not really necessary - ie then you could place the page number where you wanted in the page_title field. Not a great deal of point tho - unless you have very long titles and want users to be able to see them in the title. Unlikely though.

Web Development in Nottingham, UK by Kineta Systems

Page

TonW's picture

Any idea why Global Redirect module is redirecting with 301 node?page=* to ?page=*? Is this usual or doesnt work with 5.7?

Er well...

NikLP's picture

Perhaps you should direct that to the G_R issues queue, or check it out there to see if it's reported...?

However, IIRC, G_R simply redirects /node to /, so maybe this is expected?

Web Development in Nottingham, UK by Kineta Systems

I did the issue queue there

TonW's picture

I did the issue queue there 1 minute after i post it here, i should have made it just there. Its offtopic but anyway i dont think that it should 301 redirect all the pagination to a new one.

quick and dirty solution for the problem

bara.munchies's picture

i know it's quick and dirty, but maybe someone can write a cleaner solution for the templates.php file based on my idea. open for any improvements. would love to see your comment in the thread.

http://groups.drupal.org/node/8571

preprocess is your friend

kbahey's picture

Can't you do this simply like so:

In your theme's template.php, add this function, or modify it accordingly:

<?php
function phptemplate_preprocess_page(&$vars) {
  if (isset(
$_GET['page'])) {
   
$vars['head_title'] = $vars['head_title'] . " " . $_GET['page'];
  }
}
?>

This makes the title append a page number.

Drupal performance tuning, development, customization and consulting: 2bits.com, Inc..
Personal blog: Baheyeldin.com.

Drupal performance tuning, development, customization and consulting: 2bits.com, Inc..
Personal blog: Baheyeldin.com.

D5

Z2222's picture

Will that work in Drupal 5 with the Page Title Module installed? It didn't seem to work here...

--
My Drupal Tutorials

Drupal 6 only

kbahey's picture

I did something similar for a Drupal 6 site. Drupal 5 does not have preprocess functions, so you have to use callbacks.

And the while idea here is to avoid installing and updating yet another module, and just have a few lines in template.php rather than the overhead of modules.

Drupal performance tuning, development, customization and consulting: 2bits.com, Inc..
Personal blog: Baheyeldin.com.

Drupal performance tuning, development, customization and consulting: 2bits.com, Inc..
Personal blog: Baheyeldin.com.

Make sure $_GET['page'] is numeric :P

markus_petrux's picture

for example, doing (int)$_GET['page'].

Amen

kbahey's picture

What markus_petrux said is right. User input cannot be trusted and has to be sanitized always. check_plain() is also suitable here.

Drupal performance tuning, development, customization and consulting: 2bits.com, Inc..
Personal blog: Baheyeldin.com.

Drupal performance tuning, development, customization and consulting: 2bits.com, Inc..
Personal blog: Baheyeldin.com.

J. I am in sicily on tuesday

halisemre's picture

J. I am in sicily on tuesday i willbe back home ihave a solution for it i will let you know

in page_title module find

halisemre's picture

in page_title module find (should be around line 310)

if ($type == 'global') {
    $values['page-title'] = page_title_get_title();
}

replace it with
if ($type == 'global') {
    $values['page-title'] = page_title_get_title();
$values['pager-page'] = $_REQUEST['page'] ? t('Other Page: @page | ', array('@page' => $_REQUEST['page'])) : '' ;
  }

FIND

if ($type == 'global' || $type == 'all') {
    $tokens['global']['page-title'] = t("The page title.");
  }

REPLACE IT with:
if ($type == 'global' || $type == 'all') {
    $tokens['global']['page-title'] = t("The page title.");
$tokens['global']['pager-page'] = t('The current page if pager is in use.');
  }

after you add it to the code

halisemre's picture

after you add it to the code in page_title module enable it

johnfry made the best solution

abdobasha2004's picture

@ http://johnfry.org/blog/avoiding-duplicate-titles-drupal-pages

You can find the best solution for this

just add :
if (isset($_GET['page'])) {
$page = (int) $_GET['page'] + 1;
if ($page > 1) {
$head_title .= t(' - Page ').$page;
}
}

to the title string on top of template.php or page.tpl in your theme folder, so title tag may be like this :

<?php
if (isset($_GET['page'])) {
 
$page = (int) $_GET['page'] + 1;
  if (
$page > 1) {
   
$head_title .= t(' - Page ').$page;
  }
}
print
$head_title
?>

working on : http://100fm6.com/feeds/

The Solution

apetrisor's picture

I don't know if this is still an issue, but in the Page Title module settings, under "Pattern for pages that contain a pager:" write something like "| Page [page-number]" and you're good to go.


Alex Petrisor

Freelance web designer/developer.
Blog | Portfolio

Never noticed this feature.

brianmercer's picture

Never noticed this feature. Thanks for pointing it out. It's not perfect though since for me the page title comes out

Page Title | Site Name - Page 2

when what you really want is

Page Title - Page 2 | Site Name

and you can't do the [page-number] in your global or you get "Page 1" in the title of every page.

It does not works when sorting pages

tcibah's picture

We are using this pattern in "Pattern for pages that contain a pager":
| page [current-page-number]

It apparently does not cover all cases. Below, WMT warning that the following six pages have "Duplicate title tags":
/mysite/top-rated-percent?order=comment_count&sort=asc&page=12
/mysite/top-rated-percent?order=name&sort=asc&page=12
/mysite/top-rated-percent?order=title&sort=asc&page=12
/mysite/top-rated-percent?order=totalcount&sort=asc&page=12
/mysite/top-rated-percent?order=value&sort=asc&page=12
/mysite/top-rated-percent?page=12&order=name&sort=desc

Note
Mysite: is the folder where Drupal is located.
top-rated-percent: a Views page

The problem is obviously due to sorting….

Adding the then current Unix time stamp to the above pattern will solve it but will give a strange title!
| page [current-page-number] - [site-date-raw]

Any draw backs to using the time stamp?

Bummer

apetrisor's picture

True, and I don't see what you can do about it. Actually there are 3 options:
1 - Have Page 2 after Site Name and live with it :)
2 - Remove Site Name from the title.
3 - Hack the Page Title module? :-s


Alex Petrisor

Freelance web designer/developer.
Blog | Portfolio

For now I've subscribed to

brianmercer's picture

For now I've subscribed to the Page Title Module issue about it. :)

http://drupal.org/node/645722

headstartcms's picture

I cannot locate the location directory ? Just need assistance . . . Your response are appreciated .

Here's what I did for a D5 site (should work on others)

Simon Naude's picture

Here's what I did for a D5 site :

<?php
// 'module' is a placeholder for your module's name. You could probably use it in a theme as well.

$pagecount = module_pagecount() ; // invocation

function module_pagecount() {
 
$pagecount = '' ;
 
$questionpieces = explode('&', $_SERVER['QUERY_STRING']) ; // get k=v
 
foreach ( $questionpieces as $questionpc ) {
    if (
strpos ( $questionpc, 'page' ) !== FALSE ) { // has page
     
$qpgs = explode( '=', $questionpc ) ;
     
$pagecount = ' - Page '. ( intval ( check_plain ( $qpgs[1] ) ) +1 ) ;
    }
// end if - has page
   
else {
    
$pagecount = ' - Page 1' ;
    }
  }
// end foreach : $questionpieces as $questionpc
 
return $pagecount ;
}
?>

To use pagecount in a module, simply call the module_pagecount() function
To use page count (such as in a meta tag for a view) :

<?php
// page.tpl.php
$urlbits = explode('/', $_SERVER['REQUEST_URI']);
$pagecount = '' ;
 
$questionpieces = explode('&', $_SERVER['QUERY_STRING']) ; // get k=v
 
foreach ( $questionpieces as $questionpc ) {
    if (
strpos ( $questionpc, 'page' ) !== FALSE ) { // has page
     
$qpgs = explode( '=', $questionpc ) ;
     
$pagecount = ' - Page '. ( intval ( check_plain ( $qpgs[1] ) ) +1 ) ;
    }
// end if - has page
    //else {
    //  $pagecount = ' - Page 1' ;
    //}
 
} // end foreach : $questionpieces as $questionpc

if (in_array('part_of_page_path', $urlbits) && in_array('next_part_of_page_path', $urlbits) ) {
        print
'<meta name="Title" content="'. $head_title. '" />'."\n";
        print
'<meta name="Description" content="page description' . $pagecount .'" />'."\n";
}

?>

You could probably contribute this to the page_title module (not 'hack' the module, but actually contribute code to it).