Set paginated page to no index

#51130
  • Resolved Anonymous
    Rank Math free

    Hello,

    I’m using pagination in my blog articles <!–nextpage–>

    The problem is that Google index all second pages of my articles example : https://www.mysite.com/article/2/

    I want to set those pages to no index.

    This code did not work for me thought

    add_filter( ‘rank_math/frontend/robots’, function( $robots ) { {
    if (is_paged()) {
    return ‘noindex,follow’;
    } else {
    return $robots;
    }
    });

    What I did worng ??

    Thank you.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hello,

    Thank you for contacting Rank Math today.

    You can easily enable this feature by heading over to Rank Math > Titles & Meta > Misc Pages > Noindex Paginated Pages and enable this option.

    Looking forward to helping you. Thank you.

    Hello,

    Thank you for contacting Rank Math today.

    Since you are using the nextpage WordPress tag, you can try this code and let us know how it goes.

    global $wp_query;
    $page = $wp_query->get( 'page' );
    add_filter( ‘rank_math/frontend/robots’, function( $robots ) { {
     if ($page > 1) {
       return ‘noindex,follow’;
     } else {
       return $robots;
     }
    });

    Looking forward to helping you. Thank you.

    ​​​​​​

    Anonymous
    Rank Math free

    Hi,

    I get this error :
    Notice: Undefined variable: page in functions.php on line 210

    line 210 : if ($page > 1) {

    Thanks

    Alberto
    Rank Math business

    Hello,

    Could you try changing it like this?

    add_filter( ‘rank_math/frontend/robots’, function( $robots ) {
     global $wp_query;
     $page = $wp_query->get( 'page' );
     if ($page > 1) {
       return ‘noindex,follow’;
     } else {
       return $robots;
     }
    });

    Looking forward to help you.

    Anonymous
    Rank Math free

    Hello,

    I get this now

    Warning: A non-numeric value encountered in /wp-content/plugins/seo-by-rank-math/includes/frontend/paper/class-paper.php on line 282

    Fatal error: Uncaught Error: Unsupported operand types in /wp-content/plugins/seo-by-rank-math/includes/frontend/paper/class-paper.php:282 Stack trace: #0 /wp-content/plugins/seo-by-rank-math/includes/frontend/paper/class-paper.php(225): RankMath\Paper\Paper->advanced_robots() #1 /wp-content/plugins/seo-by-rank-math/includes/frontend/class-head.php(191): RankMath\Paper\Paper->get_robots() #2 /wp-includes/class-wp-hook.php(287): RankMath\Frontend\Head->robots() #3 /wp-includes/class-wp-hook.php(311): WP_Hook->apply_filters(NULL, Array) #4 /wp-includes/plugin.php(544): WP_Hook->do_action(Array) #5 /wp-content/plugins/seo-by-rank-math/includes/traits/cla in /wp-content/plugins/seo-by-rank-math/includes/frontend/paper/class-paper.php on line 282

    Thank you for your help!

    Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    Please make use of the following code snippet, I think there was a formatting problem on the last snippet:

    add_filter( 'rank_math/frontend/robots', function( $robots ) {
     global $wp_query;
     $page = $wp_query->get( 'page' );
     if ($page > 1) {
       $robots['index'] = "noindex";
       $robots['follow'] = "nofollow";
       return $robots;
     } else {
       return $robots;
     }
    });

    Looking forward to helping you. Thank you.

    ​​​​​​​

    Anonymous
    Rank Math free

    Perfect!! it’s working good

    Thank you so much for your help.

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 8 replies - 1 through 8 (of 8 total)

The ticket ‘Set paginated page to no index’ is closed to new replies.