0

I just changed the title tag in the header.php like this

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

Just want to change the title like "Some Text - 2/7 - Some other Text"

where 2/7 refer to total pages of 7 and current visiting page is 2

How to change the title properly

0

The way I understand this, you're trying to filter wp_title to include your pagination data.

You can change the format in the sprintf first parameter and other params as per your needs. Please use with caution.

add_filter('wp_title', function( $title ) { 

    global $paged // page number
         , $wp_query; // WordPress query data

    if( ! is_feed() && (int) $wp_query->max_num_pages > 1 ) {

        $title = sprintf(
            "%s - %d/%d - %s", // format
            get_bloginfo('name'), // blog name
            (int) $paged > 0 ? $paged : 1, // current page (goes 0 if no param set)
            $wp_query->max_num_pages, // max number of pages found
            get_bloginfo('description') // blog description
        );

    }

    return $title;

}, 999);

Hope that helps.

  • 1
    Newer themes will most likely not use the wp_title() function. – birgire May 29 '16 at 15:21
  • where do you write this function , what file to modify ? – Sanjeewa May 29 '16 at 22:28
  • Good morning. In your child theme's functions file ;) – Samuel Elh May 29 '16 at 22:32
  • Good morning to all, I'm little new to wordpress development , theme's functions file ->functions.php ? and how to call it properly in the header.php ? – Sanjeewa May 29 '16 at 23:25
  • I suggest to create a child theme. Add the snippet of code in the answer to your created child functions.php file, that's all. – Samuel Elh May 29 '16 at 23:29

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.