noindex query parameter

#339741
  • Resolved Warta B
    Rank Math free

    Hi

    im just continuing this old thread https://support.rankmath.com/ticket/query-strings-paramters-exclude/

    Basically what I would to ask is how to implement this on multiple parameters (not just single param)

     add_filter( 'rank_math/frontend/robots', function( $robots ) {
    	$url = home_url( $_SERVER['REQUEST_URI'] );
    	if(strpos($url,"?s=") !== false)  {
    		$robots['index'] = "noindex";
    		return $robots;
    	};
    	return $robots;
    });

    For example I have ?s=,?amp=,?noamp= where I like rankmath meta return noindex, tried this code on generatepress child function.php but it throws error

     add_filter( 'rank_math/frontend/robots', function( $robots ) {
    	$url = home_url( $_SERVER['REQUEST_URI'] );
    	if(strpos($url,"?q=","?max-results","?amp","?post_type","?page_id=") !== false)  {
    		$robots['index'] = "noindex";
    		return $robots;
    	};
    	return $robots;
    });

    Uncaught ArgumentCountError: strpos() expects at most 3 arguments, 6 given in wp-content/themes/generatepress_child/functions.php:5

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

    The strpos function doesn’t support multiple entries or “needles” so you would need to do it like this:

    ...
    if (strpos($url,'?s=') !== false || strpos($url,'?amp=') !== false || strpos($url,'?noamp=') !== false) {
      $robots['index'] = "noindex";
    		return $robots;
    }
    ...

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    thank you works perfectly

    Azib Yaqoob
    Rank Math business

    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 3 replies - 1 through 3 (of 3 total)

The ticket ‘noindex query parameter’ is closed to new replies.