Rank math “index” conflict with wordpress native “noindex”

#133378
  • Resolved Quentin
    Rank Math free

    Hello guys,
    I use the code below to add “noindex” to many garbage links that consume the crawl budget of search engines. But on the affected pages, there is in the page header the meta of rankmath showing “index”. It only a half page later that the “noindex” activated with the code below is shown.
    Is it possible to add that noindex with your plugin ?
    I’d like to do it with all the pages that contain these url parts :
    ?wmc-currency=
    ?v=
    ?ref=

    Here is the code I use in theme functions :

    function add_noindex( $content ) {
    global $post;

    $terms = wp_get_post_terms( $post->ID, ‘product_cat’ );
    foreach ( $terms as $term ) $categories[] = $term->slug;

    if ( in_array( ‘bundles’, $categories ) || isset( $_GET[‘wmc_currency’]) ) {
    echo ‘<meta name=”robots” content=”noindex, nofollow”>’ . $content;
    }
    }
    add_filter(‘wp_head’, ‘add_noindex’);

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

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for the delay and for any inconvenience this issue may have caused you.

    You can use the code below and put it on your theme’s functions.php.

    This code ran when your URL got any of the params ?wmc-currency=, ?v=, ?ref= it will automatically assign your meta robots as noindex.

    add_filter( 'rank_math/frontend/robots', function( $robots ) {
    	if(isset($_GET['wmc-currency']) || isset($_GET['v']) || isset($_GET['ref'])){
    		$robots['index'] = 'noindex';
    	}
    	return $robots;
    }); 

    I hope that helps. Thank you, and looking forward to your update.

    Awesome guys. Maybe it’s better to ad nofollow to, how to do that ?

    Hi,

    You can add this to the code:

    
        $robots['follow'] = "nofollow";
    

    Hope it helps

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

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

The ticket ‘Rank math “index” conflict with wordpress native “noindex”’ is closed to new replies.