How to change title tags on paginated posts?

I’ve created many post with multiple pages with the nextpage-tag. The problem is that these show up as errors in “Google Webmaster Tools” because of duplicate title tags and meta descriptions.

The urls are like this:

Read More
http://mypage.com/mypost/
http://mypage.com/mypost/2
http://mypage.com/mypost/3

all of which have the same title and meta tags.

Is it somehow possible to include the page number to the meta tags?

I’m using the “WP SEO” which surprisingly doesn’t have this feature.

Related posts

Leave a Reply

5 comments

  1. Is “WP SEO” = “WordPress SEO by Yoast”? If so, the plugin has some tags for you:

    • %%page%% – Replaced with the current page number (i.e. page 2 of 4)
    • %%pagetotal%% – Replaced with the current page total
    • %%pagenumber%% – Replaced with the current page number

    Just look at the bottom of the page wp-admin/admin.php?page=wpseo_titles, you’ll see. Just try it.

  2. Try using the $page global to filter wp_title:

    <?php
    function wpse24661_filter_wp_title( $title, $separator ) {
        // Globalize $page
        global $page;
    
        // Determine if current post is paginated
        // and if we're on a page other than Page 1
        if ( $page >= 2 ) {
            // Append $separator Page #
            $title .= ' ' . $separator . ' ' . 'Page ' . $page;
        }    
        // Return filtered $title
        return $title;
    }
    add_filter( 'wp_title', 'wpse24661_filter_wp_title', 10, 2 );
    ?>
    
  3. Above answer is not working due to global variable issue, we have to use ‘$paged’ instead of ‘$page’.
    Following is updated solution

    function wpse24661_filter_wp_title( $title, $separator ) {
        // Globalize $page
        global $paged;
    
        // Determine if current post is paginated
        // and if we're on a page other than Page 1
        if ( $paged >= 2 ) {
            // Append $separator Page #
            $title .= ' ' . $separator . ' ' . 'Page ' . $paged;
        }    
        // Return filtered $title
        // echo $title;die;
        return $title;
    }
    add_filter( 'wp_title', 'wpse24661_filter_wp_title', 101, 2 );
    
  4. I have tried your method. But it’s not get reflected in page title on blog pagination. Just hook the wp_title as mentioned the same in functions.php and ensure the same it’s not working can you update any other ways to achieve it.