1

With the reference of below questions.
How to change title tags on paginated posts?
Paginate tags page
How to change title tags on paginated posts?
Add Page number to Meta Description in Wordpress SEO by Yoast

I am using WP Page Numbers plugin for pagination But plugin didn't offer different options.

I would like to add different title tag for each page in my pagination pages. Below are different pages

Pagination for all Index pages (50 pages and increasing)
http:// domain.com/page/2/

Pagination for all Categories(20 pages each in 4 categories and increasing)
http:// domain.com/this-is-category-no-1/page/2/
http:// domain.com/this-is-my-cat-no-2/page/3/

  • Please clarify how this question is specific to WordPress, rather than specific to WP Page Numbers Plugin code. – Chip Bennett Nov 7 '13 at 15:30
  • Thanks @ChipBennett Infact I don't want to use plugin. that is why requesting code – muhammad usman Nov 7 '13 at 16:16
  • Plugin recommendations are inherently off-topic for WPSE. All answers involve actual code. Thus, "without a Plugin" is an arbitrary and invalid limitation. Also: you indicate in your question that you're already using a Plugin, and this question seems to be specific to the code generated by that Plugin. – Chip Bennett Nov 7 '13 at 16:21
0

Do you use a query to display results on each page?

If you know the query arguments then you can do stuff based on the output. Let's say 'posts_per_page' is set to 20. You can use found_posts to count how many posts there are, and show a title tag based on that info:

$num_posts = $my_query->found_posts;

// For index pages
if(is_page('page_title_here') && $num_posts / 20 == 4){
     // Now you're on page 4
}

// For category pages
if(is_category('category_title_here') && $num_posts / 20 == 3){
     // Now you're on page 3
}

If you have 'paged' set to $paged and you've defined $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; then you can make if statements based on the page number (nicer than the above code IMO):

// For index pages
if(is_page('page_title_here') && $paged == 4){
     // Now you're on page 4
}

// For category pages
if(is_category('category_title_here') && $paged == 3){
     // Now you're on page 3
}

I'm actually not sure what you mean by title tags, but you can do anything you like in within the if statements.

UPDATE

If you want the code to put the title in the <title> tag in the <head> section, wrap the code in a function:

function title_function(){
    // For index pages
    if(is_page('page_title_here') && $paged == 4){
         return 'Title for page 4 on page_title_here';
    }

    // For category pages
    if(is_category('category_title_here') && $paged == 3){
         return 'Title for page 3 on category_title_here';
    }
}

And put

<title><?php echo title_function(); ?></title>

UPDATE 2

I misread the question, instead of is_page in the code above, use is_home() if your page shows recent posts, or is_front_page() if your homepage is a static page:

function title_function(){
    // For homepage
    if(is_home() && $paged == 4){
         return 'Title for page 4 on page_title_here';
    }

    // For category pages
    if(is_category('category_title_here') && $paged == 3){
         return 'Title for page 3 on category_title_here';
    }
}
  • 1
    by title tag i mean <title>Title Tag</title> – muhammad usman Nov 7 '13 at 17:52
  • OK, I've updated the answer. – eskimo Nov 7 '13 at 18:02
  • Thanks you very much. this has been very difficult for me. – muhammad usman Nov 7 '13 at 22:23
  • for the first condition i think instead of is_page, is_home() is better because it is working for me :). Please change it because i have to accept the answer. thanks again – muhammad usman Nov 7 '13 at 22:29
  • wordpress.stackexchange.com/questions/121630/… @joostvanhoof would you please answer this as well please – muhammad usman Nov 7 '13 at 23:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.