Where to find Malcolm Coles, reviews, and tips on how to do things I couldn’t do.

malcolm coles


Adding page numbers: How to avoid duplicate titles and meta descriptions in pages 2 and higher of Wordpress category and tag pages 24

Posted on December 20, 2008 by Malcolm Coles

I have written before of the problems of Wordpress comment pagination and duplicate content and how to get unique meta descriptions in wordpress.

I have now solved the problem of all pages in the Wordpress loop having identical titles and meta descriptions.

The problem

Whether it's your main index page or a category or tag page, Wordpress works in the same way. It shows the latest, say, 10 posts. And it then gives you a next link to click. If you click next, the URL will be very similar, but will have /page/2/ on the end. And it will show the next posts.

However, this second page (and any third, fourth, fifth etc pages) will all have the same titles and meta descriptions. This will confuse google.

The solution

The answer is to include the page number in the title and meta description of subsequent pages of the loop.

Here's some code to let you do this:

<?php if ( $paged < 2 ) { } else { echo (' Page '); echo ($paged);} ?>

What this does is to check whether the page is the first one or is page 2 or higher.

If it's page 1, nothing happens. On page 2 or higher, it adds: Page 2 (or 3, or whatever).

So just add this code after the code that is generating your meta description or title.

An example

The code to generate my title looks like this:

<title><?php wp_title('&raquo;', true, 'right'); ?> <?php bloginfo('name'); ?>
<?php if ( is_home() ) {echo (' - Reviews, SEO, wordpress, how to do things ...');}
?>
<?php if ( $paged < 2 ) {
} else {
echo (' page ');
echo ($paged);
} ?>
</title>

So if you go here, it should say 'page 2' at the end of the title (check your browser bar to see it).

You might also like
  1. Avoid duplicate content with paged comments in wordpress
  2. Unique meta description and meta keyword tags in your Wordpress themes
  3. Wordpress comment pagination & duplicate content
  4. Twitter's latest SEO improvement: meta descriptions
  5. Can you use rel = canonical to fix duplicate comment problems caused by comment pagination in wordpress?

You should follow me on Twitter.

24 Responses to “Adding page numbers: How to avoid duplicate titles and meta descriptions in pages 2 and higher of Wordpress category and tag pages”

  1. Laurens says:

    Nice work-around but unfortunately I am using the All-in-one SEO plugin and this trick doesn't seem to apply to it. If anyone knows of a way of getting this working with that plug-in, it would be very useful for a lot of people.

  2. Chris says:

    I've recently had to add unique meta descriptions into WordPress but so far none of my posts have been long enough to require a second page and I had not considered this issue.

    I'll now add this solution into my blog so that I don't run into problems when I do create posts long enough for a multiple pages.

    Many Thanks.

  3. Laurens - because All In One Seo generates the titles and meta descriptions itself, you can't use this trick with it. Well, you could - you could rewrite the PHP in the plug-in. Let us know how you get on!!!

  4. Greg says:

    All in one does not generate meta keyword and descriptions for Paged pages, or Tag pages, at least not for me. It deals with the Tag page titles and the Paged page titles, but not the meta. To get meta data in those groups of pages, I added two parts of code, one for the Tag pages, the other for the Paged pages in the theme header.php file. I'm not a programmer (or even close), so here is the code I assembled from various sources (here included) to have a go at. I assume it could be done more compactly or elegantly or both, but it works! The object was to have a different description for each Tag page by dynamically inserting the title of the Tag page in the front of the description in a grammatically correct way, and for each Paged page by dynamically inserting the page number in a readable fashion as well. And when I say it works, it means I don't know what it might be screwing up.... but that the meta appears in the source code of the Paged and Tag pages and everything seems OK.

    <?php if (is_tag()) { ?>
    <meta name="description" content="<?php single_tag_title(''); ?> at my description"/>
    <meta name="keywords" content="my keywords"/>
    <?php } ?>

    <?php if (is_paged()) { ?>
    <meta name="description" content="<?php if ( $paged < 2 ) { } else { echo ('Blog Page '); echo ($paged);} ?> at at my description"/>
    <meta name="keywords" content="my keywords"/>
    <?php } ?>

  5. Greg says:

    Hi Malcom. I did come across one issue with the code. If the page is a TAG page that is the second page for a particular Tag (we have 15 posts per page, so a Tag that was attached to more than 15 posts would create a second page), wordpress treats this 2nd page as a Paged page in addition to a Tag page and with my code, puts up both sets of meta data on that page. Any suggestions for a code fix to resolve this.... such as if it's a Tag, then don't go to step 2 (the paged step) in the code.... something like that?

    • This is what I do if it's any help (NB the Metadescription bit is a custom field). You could check out Christian's site - he's edited the all in one plugin to include the method described here.

      <meta name="description" content="
      <?php
      if(is_home()) {echo ('Malcolm Coles: His blog for his reviews, so you can find him, and other stuff that takes his fancy.');}
      else
      {if(is_category()) {echo category_description();}
      else {if(is_tag()) {echo '-tag archive page for this blog' . single_tag_title();}
      else {if(is_month()) {echo ' archive page for this blog' . the_time('F, Y');}
      else {echo get_post_meta($post->ID, "Metadescription", true);}
      }}}
      ?>
      <?php if ( $paged < 2 ) {
      } else {
      echo (' Page '); echo ($paged);
      } ?>">

  6. Greg says:

    HI Malcom. I'm sure your code is better... since I don't have a clue!!! I will look at it, and get back. I did resolve the issue of when something is both a Tag and Paged....not duping the meta tags (one set for each)... which is half good news :) . I'll get back in the next day or two after looking more at the code.... Thanks Malcom........

  7. Come faccio per says:

    Dearest, i have a problem... For metadescription I use the plugin headspace, but i'm havin issues since all homepage pages > 2 have the same metadescription( categories and tags too).
    Is there anway i can solve this while using HeadSpace?

  8. andre says:

    Hello,

    I read your piece with interest, as I've been having some serious issues with duplicate meta descriptions.

    I use Wordpress 2.8, and their code to break up long posts into two or more pages.
    I've just begun using the "All in One SEO" plugin, which auto-generates the description tags using the first 20 or so words of each post.

    The problem is that the generated meta descriptions for **all** pages are those found on the **first** page of each post.

    See:

    http://www.altfg.com/blog/awards/oscar-2009-academy-invites-new-members/

    http://www.altfg.com/blog/awards/oscar-2009-academy-invites-new-members/2/

    (I've tried two or three different "meta descritpion" or "SEO" plugins, and they've all come up with the same duplicate meta descriptions.)

    I was wondering if someone here can suggest a code "addition" to prevent those duplicate meta descriptions; one that I could insert either into my blog's theme's coding, or into the "All in One SEO" code itself, which is the following for the meta descriptions for individual posts (that I could see):

    if (is_single() || is_page() || $this->is_static_posts_page()) {
    if ($this->is_static_front_page()) {
    $description = trim(stripcslashes($this->internationalize(get_option('aiosp_home_description'))));
    } else {
    $description = $this->get_post_description($post);
    }

    AND/OR (further down below the plugin's code)

    function get_post_description($post) {
    $description = trim(stripcslashes($this->internationalize(get_post_meta($post->ID, "description", true))));
    if (!$description) {
    $description = $this->trim_excerpt_without_filters_full_length($this->internationalize($post->post_excerpt));
    if (!$description && get_option("aiosp_generate_descriptions")) {
    $description = $this->trim_excerpt_without_filters($this->internationalize($post->post_content));
    }

    I should add that I've already posted queries in the Wordpress, Google, and All in One SEO forums, but so far (it's been several days) I haven't found a solution to this issue. Perhaps someone here can help me out.

    Any assistance would be much appreciated.

  9. andre says:

    Malcolm,
    Thanks for the quick response.
    I tried using Christian Schenk's code for meta descriptions but I can't get the following into the functions.php page:

    function paged_meta_description_filter($content) {
    global $cpage;
    if ($cpage < 1) return $content;
    return $content.' - '.__('comment page').' '.$cpage;
    }

    It simply won't accept it when I save the file. (The addition is deleted.)

    The "if function exists" segment is fine. I can paste it there. But the code above is always rejected. Any idea where else in the theme's php pages I could place it?

  10. As I don't use AIOSEO, I don't have a clue I'm afraid. I'd ask Christian on his site?

    However, it's not just the meta description you have problems with - the title tag is the same on both pages as well.

    I would avoid pagination from an SEO point of view (it's always problematic in practice, even if in theory it should be doable) and user experience point of view (I hate it! But also the links don't stand out. And page numbers give no reason to click - they don't tell you anything about what's there).

    I can see why you need it on that article as it is so long. But why not chop it into two separate ones instead? One with your commentary, and one with a full list of new members. That way you can link between them with keyword-rich anchor text, rather than "1" and "2". And no duplicate title / description problems.

  11. Andre says:

    Malcolm,
    Thanks for the suggestion -- and, in fact, I've decided to act on it. Getting those title tags and meta descriptions to work on pages 2, 3, etc. has been a time-consuming nightmare.
    As you said, pages such as the one you visited should be broken into two, but as two separate posts.
    I've already begun the updating process.
    Thanks again.

  12. Hi Malcom, I added the number of page (es: pagina y di x) into every metadescription for all the pages >2 but Google still found them as duplicate o_o Any suggestion?it's drivin me crazy! thank u Valentina

Leave a Reply

All comments are moderated. Comments that include URLs and which just say 'Nice post' or similar won't be published, but thanks for the sentiment.

Find more posts like this



↑ Top