WordPress Tricks

Show Page Number in Paginated post’s title ,Site title and in Meta description for SEO purpose

page number in paginated page titles and in Site title and meta description

Before i shared you a post about “show/break large post with pagination and to show Next Page and Previous page instead of pagination number” today i am sharing you another issue about large post where you split the post with pagination. Here i am showing you to show Page Number in Titles when u click on Next Page or Previous page and to show same page number in Site Title and in Meta description. This is needed due to SEO purpose. This snippet of code is for Advanced wordpress users, please use this code before taking backup.

This code will go in Single Post template

<?php the_title();if ( $paged >= 2 || $page >= 2 ) echo ' | ' . sprintf( __( 'Page %s'), max( $paged, $page ) ). ""." of ".$page; ?>

This code will go in function.php

if ( ! function_exists( 'add_page_number' ) )
{
    function add_page_number( $s )
    {
        global $page;
        $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
        !empty ( $page ) && 1 < $page && $paged = $page;
         $paged > 1 && $s .= ' - ' . sprintf( __( 'Page %s' ), $paged );
         return $s;
    }
    add_filter( 'wpseo_title', 'add_page_number', 100, 1 );
    add_filter( 'wpseo_metadesc', 'add_page_number', 100, 1 );

}

*** If you are not experienced enough to edit theme file please feel free to ask help in the comments section.
Or
You can take my personal help in skype : om2000_cuet

2 thoughts on “Show Page Number in Paginated post’s title ,Site title and in Meta description for SEO purpose”

  1. Hi, I’m trying to use this script to add the page number to the category/archive pages and for some reason it’s pulling in the title of the first post instead of the category title page #. Any ideas?

    Thanks!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s