Hi. I have a similar issue to the above so just want to make sure the code I am adding is relevant to my site and the URL strong.
Below is the URL string when a filter is applied to a page:
https://www.webiste.com/hardware/?min_price=150&max_price=200&filter_finish=dark-bronze&tax_product_cat=cabinet&filter_size=128mm&unfilter=1
I have added the following code to my Theme functions.php file:
// Noindex filter queries
add_filter( 'rank_math/frontend/robots', function( $robots ) {
$url = home_url( $_SERVER['REQUEST_URI'] );
if (strpos($url,'?min_price=') !== false || strpos($url,'?max_price=') !== false || strpos($url,'?filter_finish=') !== false || strpos($url,'?tax_product_cat=') !== false || strpos($url,'?filter_size=') !== false || strpos($url,'?filter_backset-size=') !== false) {
$robots['index'] = "noindex";
$robots['follow'] = 'nofollow';
};
return $robots;
});
Is this correct and the Filter page URLs will no longer be indexed by Search Engines?
Many thanks, Jamie