• Resolved Natalya

    (@nalitana)


    Hello! Tell me, please, how to add a page number to each title and description in an article with a pangination? In the Yoast plugin for this purpose I used this function:

    /** Add Page Number to Title and Meta Description for SEO **/
    if ( ! function_exists( 'multipage_metadesc' ) ){
       function multipage_metadesc( $s ){
          global $page;
          $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
          ! empty ( $page ) && 1 < $page && $paged = $page;
          $paged > 1 && $s .= ' - ' . sprintf( __( 'Part %s', 'theme' ), $paged );
          return $s;
       }
       add_filter( 'wpseo_metadesc', 'multipage_metadesc', 100, 1 );
    }
    if ( ! function_exists( 'multipage_title' ) ){
       function multipage_title( $title ){
          global $page;
          $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
          ! empty ( $page ) && 1 < $page && $paged = $page;
          $paged > 1 && $title .= ' - ' . sprintf( __( 'Part %s', 'theme' ), $paged );
          return $title;
       }
       add_filter( 'wpseo_title', 'multipage_title', 100, 1 );
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Rank Math

    (@rankmath)

    Hello @nalitana

    Thank you for your message.

    Please try the following code:

    /** Add Page Number to Title and Meta Description for SEO **/
    if ( ! function_exists( 'multipage_metadesc' ) ){
       function multipage_metadesc( $s ){
          global $page;
          $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
          ! empty ( $page ) && 1 < $page && $paged = $page;
          $paged > 1 && $s .= ' - ' . sprintf( __( 'Part %s', 'theme' ), $paged );
          return $s;
       }
       add_filter( 'rank_math/frontend/description', 'multipage_metadesc', 100, 1 );
    }
    if ( ! function_exists( 'multipage_title' ) ){
       function multipage_title( $title ){
          global $page;
          $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
          ! empty ( $page ) && 1 < $page && $paged = $page;
          $paged > 1 && $title .= ' - ' . sprintf( __( 'Part %s', 'theme' ), $paged );
          return $title;
       }
       add_filter( 'rank_math/frontend/title', 'multipage_title', 100, 1 );
    }

    Hope that helps.

    Thread Starter Natalya

    (@nalitana)

    Wow! Thank you very much for your help!

    Plugin Author Rank Math

    (@rankmath)

    Hello @nalitana

    Glad that helped.

    If it isn’t too much to ask for – would you mind leaving us a review here?
    https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post

    It only takes a couple of minutes but helps us tremendously.

    It would mean so much to us and would go a really long way.

    Thank you.​​

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to add a page number to each title and description’ is closed to new replies.