How to
SEO advice
Categories: How to, Wordpress. Tags: ,

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

December 20, 2008 42 Comments

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);
} ?>

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?

Share this post

Follow me on Facebook or Twitter


  • 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.

  • 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.

  • 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!!!

  • 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 } ?>

  • 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="
      if(is_home()) {echo ('Malcolm Coles: His blog for his reviews, so you can find him, and other stuff that takes his fancy.');}
      {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);
      } ?>">

  • 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........

  • 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?

  • andre says:


    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.


    (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.

  • andre says:

    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?

  • 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.

  • Andre says:

    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.

  • 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

  • andrei says:

    Thanks a bunch! This is the only place I was able to find the answer to page numbers in title problem I had on my blog!

  • Anup says:

    Nice coding tip. I have used it with title and canonical link plugin. thanks.

  • Lachlan says:

    Thanks for this post. I'm wondering if there is a way to check if it is a specific tag page, and ALSO check what tag page number it is?

    I'm fine with the first bit, e.g.

    if ( is_tag('ipad-accessories') ) {
    echo 'My Special Page Title

    But I really just want this to be for the first tag page, not tag page 2, 3 ,4 etc, which is what I get at the moment.

    So the logic would be
    If is_tag('ipad-accessories') AND is tag page 1

    Any tips appreciated muchly, I'm new to PHP and I'm still learnign the syntax.

    • Lachlan: You mean you just want the title to appear on page one and not any subsequent pages?

      You just reverse the logic of this don't you:
      {?php if ( $paged < 2 ) { } else { echo (' Page '); echo ($paged);} ?}
      (pointy brackets replaced by {} to stop the code getting mangled by wodpress)
      So change the < 2 to > 2 ...

  • Greg Z says:

    Hi Malcom. You helped me a long time ago:) in this very thread. Hope all is well your way.

    Lachlan - examples of code I use:

    Here is some code to make sure meta descriptions on the tag page and paged pages of the tag (pages 2 thru whatever) are different which I use on my site, and which uses essentially the code Malcom posted above. The code starts off the meta desc with the tag title, or the tag title and "Page _". if it's a paged tag page, and G has no problem with it being duplicate

    <meta name="description" content="<?php if ( $paged whatever you want to say for your meta description"/>

    Also, the following snippets will work to differentiate between tag first page and the paged pages (an can be used for search pages, etc as well):

    if ( (is_tag() ) && !( is_paged())) THIS SAYS A TAG THAT IS NOT A PAGED PAGE (THE ! AFTER THE && MEANS NOT) ... so this singles out the first TAG page


    if ( (is_tag() ) && ( is_paged())) THIS SAYS A TAG THAT IS ALSO A PAGED PAGE (ALL BUT THE FIRST TAG PAGE)


  • Greg Z says:

    Hi Malcom. The comment I left cut out part of the code for the meta description.... here is the complete code for the first part of the comment. Hope it all goes thru.

    <meta name="description" content="<?php if ( $paged whatever you want to say in your meta desc"/>

  • Greg had to email me the code in the end to stop wordpress cutting it off. Here's what he emailed.
    Edit: oh for god's sake, stupid wordpress. Here it is with the pointy brackets replaced by square brackets. So you need to replace [ with < and ] with >

    [?php if (is_tag()) { ?][/code]
    [meta name="description" content="[?php if ( $paged < 2 ) {echo single_tag_title(''); } else {echo single_tag_title(''); echo (' Page '); echo ($paged);} ?] whatever you want in your meta description"/]
    [?php } ?]

  • Kank says:

    Hello people, i have recently started working on WP and found the problem of duplicate meta tags and duplicate meta description. i somehow figured it out dat it because wordpress uses some cpage=1 or cpage=2 for second page of the category.

    I am using All in one SEO plugin and need this duplicacy from the site.
    i read all the posts on this page, bt was a little confused about the codes. so can any1 plz plz write a reply for me so dat i can implement it in AIOSEO and get the problem corrected. plz tell me where to put the code and does it works fine or not..

    thanks a lot in advance to all

  • Will says:

    Hi Martin,

    I found Christian's code didn't work for me (in fact the example he gave doesn't have page numbers?!). I just made a hack of my own. check out this thread:

    It's fairly basic and I offer no guarantees, but it works for me.



  • Andrew says:

    Hi, i have the same problem with my blogger blog. When i check my site in webmaster tools, am told that i have duplicate title and description. How can i change it?

  • Jesica says:

    I am using ultimate seo plugin, is there a workaround to avoid and fix duplicate content already reaches five thousand my content ...
    please help me??

  • Mark says:

    Is there any way of solving this if you're using Yoast WordPress SEO plugin?

    This is driving me mad.

  • Tanner says:

    Been looking for this fix for awhile - thanks!

    FYI, you may want to wrap the sample code itself in code brackets, like so:

    echo (' page ');

    As it is, WordPress has converted all single-quotes to smart quotes and anyone who tries to cut and paste your code will break their WP page.

  • David says:

    Hey Malcolm, great content on your blog...i keep coming back to it all the time...anyway, this post was not useful to me since I cant apply this to my theme

    I use Thesis theme and tried this out but it does not seem to work
    I dont have any seo plugins since there is no need to if your are using thesis theme..

    My domain looks like this..

    where the pages are previous older posts...didnt have any problems with this but recently google webmaster tools is saying that I have double meta description tags...

    How do I fix this in Thesis theme?

    PLEASE help, I have been looking for a solution for days and havent found any, dont usually ask for help until I have done everything there is to solve a problem myself but at this point I cant...

    How do I solve this?

    Was thinking about disallowing page2, page3 and so on in robots.txt
    but dont know if this is a good idea...

    What to you suggest I do?

    Thank you very much in advance for your help and waiting for your reply...

  • Not too sure about the thesis code, sorry. But you need to find the bit of code, somewhere in the header or possibly the functions file, that creates the meta description and html title. One way is to search the folder on your desktop with the thesis files for the word title and the word meta ...

    I wouldn't disallow the pages, or you'll restrict Google's ability to find posts.

    And I wouldn't worry about it too much. Google's used to blogs with these duplicate problems and I doubt they'll cause you any problems in practice.


  • David says:

    Thanks for the quick response Malcolm

    The thesis theme is pretty complicated, can't find anything like that..

    By the way, after google spotted this my rankings went down and I dont think its a coincidence since they were stable for a very long time

    Therefore its really important for me to fix it.... If you could by any chance take a look at thesis theme i would really appreciate it, Im sure you will find where to put in the code in no time, but for a guy like me that does not have that much php knowledge is impossible... can zip the files and send them to you...

    I understand if you don't have the time but you would really help me out a lot if you could do this...

    Thanks in advance..

  • David says:

    Hi again Malcolm

    sorry for spamming your blog with my second comment, just wanted to tell you that after a couple of hours I have finally found where to put in the php code in thesis theme

    there is only one problem left

    <?php if ( $paged

    this code makes 2 different titles on all the pages
    first title is the original title and the text Page2 after that

    then under it there is second title that adds Reviews, SEO, wordpress, how to do things ...+ home page name

    I would like only 1 title tag on all of the pages, not 2.... the only difference is to add page 2,3.. to the title on all the other pages eccept home page

    But the second problem is meta description...which basically is my main problem....I would like different meta descriptions on pages 2,3.... than home page

    Could you please right down a piece of code that does that?

    I promise that I wont bug you more after that :)


  • David says:

    <meta name="description" content=" at my description"/>

    <meta name="description" content="<?php if ( $paged at at my description"/>


    This code for instance works with one little problem
    it does not remove the original title and meta description on page 2, 3 and so adds new meta and title so now I have 2 different title and meta tags.....all I need is a little tweak in this code so the original title and meta description dont show up on 2,3,4....

  • You need to nest the page bit inside the other tag (rather than add a second meta description tag)...

  • David says:

    Don't have any php knowledge... have tried different variations from the code on this post but no matter what the meta description does not change...all that happens is that there is a new meta description added... so now there are 2 descriptions at the same time which I can imagine is even worse than a duplicate one :)

    Would appreciate if you could write down that piece of code if you can, this little thing knocked my site a couple of places in I just have to get it fixed and I don't know anyone that has the knowledge to help me out..also there is nothing on this anywhere...would be really great if you could give me the code...

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.