I am using a rankmath file in the theme editor for overriding canonical issues do have a look at it
Also sharing the code which i think might be creating issues, updated code would be appreciated
add_filter(‘rank_math/frontend/robots’, function ($robots) {
// making all filtering url no index
if (is_product_category() && isset($_GET[‘filtering’])) {
$robots[‘index’] = ‘noindex’;
}
// Noindex for specific pages based on URL structure – making specific pages no index
elseif (is_page([‘my-account’, ‘checkout’, ‘cart’, ‘newsletter’, ‘social-login’, ‘maintenance’])) {
$robots[‘index’] = ‘noindex’;
}
// Check if the URL contains a question mark (indicating a query string) – also setting all page with /all/ slug in it which represent attributes with archived enabled – and lastly all paginated url as no index
if (strpos($_SERVER[‘REQUEST_URI’], ‘?’) !== false || strpos($_SERVER[‘REQUEST_URI’], ‘/all/’) !== false || strpos($_SERVER[‘REQUEST_URI’], ‘/page/’) !== false) {
$robots[‘index’] = ‘noindex’;
}
// making product as index – initially i was controlling follow/nofollow too but its a bogus thing – which i figured our later
elseif (is_product()) {
$robots[‘index’] = ‘index’;
// global $product;
// echo($product->get_id());
// if($product->get_stock_status()!=”instock”){
// $robots[‘nofollow’] = ‘follow’;
// }
// else{
// $robots[‘follow’] = ‘nofollow’;
// }
}
return $robots;
});
Hello,
Thank you for contacting Rank Math and bringing your concern to our attention.
We’ve checked the URLs you shared, but all of them are already set to index.
Could you please confirm whether you have already resolved this?
If not yet, let us know where you are seeing the noindex. You can upload screenshots using this tool and add the link here.
Looking forward to helping you.
Yes i udpated the code and removed this line
// making all filtering url no index
if (is_product_category() && isset($_GET[‘filtering’])) {
$robots[‘index’] = ‘noindex’;
}
this fixed the issues, but it dones’t make sense. If filtering isn’t applied then why was it marking pages to noindex.
This line definiately is the culprit
Hello,
Thank you for the update and for pinpointing the culprit. That snippet:
if ( is_product_category() && isset( $_GET['filtering'] ) ) {
$robots['index'] = 'noindex';
}
will mark any category archive as noindex if any filtering
parameter exists in the URL, even if it’s empty or added by another plugin/theme. To prevent false positives, try the following instead:
1. Only noindex when an actual filter is applied
Change your check to verify the value isn’t empty:
add_filter( 'rank_math/frontend/robots', function( $robots ) {
if ( is_product_category() && ! empty( $_GET['filtering'] ) ) {
$robots['index'] = 'noindex';
}
return $robots;
} );
This ensures pages without a true filtering
value stay indexable.
We hope this helps. Please let us know if you have further questions or concerns.
Thank you.
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.