Hello,
Thank you so much for getting in touch.
Currently, we don’t have a direct setting to set NoFollow to the search result pages.
The reason is that there is no utility of such a feature. People don’t link out to their search results. They are generated on the fly so a nofollow option is not really needed.
You can, however, use this filter code to change the follow attribute:
add_filter( 'rank_math/frontend/robots', function( $robots ) {
$url = home_url( $_SERVER['REQUEST_URI'] );
if(strpos($url,"your-search-page") !== false) {
$robots["follow"] = 'nofollow';
}
return $robots;
});
Here is a guide you can follow to add the filter:
https://rankmath.com/kb/wordpress-hooks-actions-filters/
Let us know how it goes.
Looking forward to helping you.
Thank you.
I have a Search Result URL like this (https://blog.testing.com/en/?s=testing) and I want to make this URL ‘nofollow’. I’m using a provided script along with the WP Code – Code Snippet Plugin as follows:
php
Copy code
add_filter( ‘rank_math/frontend/robots’, function( $robots ) {
$url = home_url( $_SERVER[‘REQUEST_URI’] );
if(strpos($url, ‘https://blog.testing.com/en/?s=testing’) !== false) {
$robots[‘follow’] = ‘nofollow’;
}
return $robots;
});
Is the above code correct and can it be used for the next step, or does it need any corrections?
Hello,
That code will only work for search query “testing” and will not work on other searches so to make it work globally, please refer to this code below instead:
add_filter('rank_math/frontend/robots', function ($robots) {
$url = home_url($_SERVER['REQUEST_URI']);
if (strpos($url, 'https://blog.testing.com/en/?s=') !== false) {
$robots['follow'] = 'nofollow';
}
return $robots;
});
Let us know how that goes.
Looking forward to helping you.
Can I use a Wildcard function in the script? In my case, I have three languages for which I want to apply ‘nofollow’.
Is the script I created correct?
add_filter(‘rank_math/frontend/robots’, function ($robots) {
$url = home_url($_SERVER[‘REQUEST_URI’]);
if((strpos($url,’https://blog.testing.com/*/search/’) !== false ||
strpos($url,’https://blog.testing.com/*/?’) !== false ||
strpos($url,’https://blog.testing.com/*/?’))
!== false ){
$robots[‘follow’] = ‘nofollow’;
}
return $robots;
});
Please let me know if this script is appropriate
add_filter(‘rank_math/frontend/robots’, function ($robots) {
$url = home_url($_SERVER[‘REQUEST_URI’]);
if((strpos($url,’https://blog.testing.com/*/search/?;) !== false ||
strpos($url,’https://blog.testing.com/*/?;) !== false ||
strpos($url,’https://blog.testing.com/*/?;))
!== false ){
$robots[‘follow’] = ‘nofollow’;
}
return $robots;
});
Hello,
Unfortunately, the filter will not work this way. However, can you please confirm if you want to nofollow all the URLs with query parameters? If so, then you can use the following filter on your website:
add_filter('rank_math/frontend/robots', function ($robots) {
$url = home_url($_SERVER['REQUEST_URI']);
if (strpos($url, '/?') !== false) {
$robots['follow'] = 'nofollow';
}
return $robots;
});
This filter will work for all of your language pages.
Let us know how it goes. Looking forward to helping you.
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.