-
Hi team,
We’re planning to switch to RankMatch Pro from Yoast Premium and currently trying the free version of RankMath on a staging environment.
Internally, we have a use-case, where we define the robots via headers (X-ROBOTS-TAG) and we remove the “robots” meta tag from the HTML.
In Yoast, we’re able to do this with the following filters
add_filter('wpseo_robots', '__return_false');
add_filter('wpseo_googlebot', '__return_false'); // Yoast SEO 14.x or newer
add_filter('wpseo_bingbot', '__return_false'); // Yoast SEO 14.x or newer
Is it possible to do it with RankMath too?
I already tried “rank_math/frontend/robots” but couldn’t make it work.
add_filter( 'rank_math/frontend/robots', function( $robots ) {
return array();
});
Thank you.
-
Hello,
Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for any inconvenience this issue may have caused you.
You should be able to remove Advanced Robots Meta from Rank Math > Titles & Meta > Advanced Robots Meta and untick the robots that you don’t want to be displayed.
However, the follow and index will still be shown as it is a default from Rank Math to generate it.
To remove them, please use this filter:
/** * Rank Math: filter the robots meta data. * * @param array $robots The meta robots directives. */ add_filter( 'rank_math/frontend/robots', function( $robots ) { unset( $robots['index'] ); unset( $robots['follow'] ); return $robots; });I hope that helps.
Thank you.
It didn’t work.
Unsetting both “index” and “follow” from $robots works the same as returning an empty array.
When I return an empty array or unset both “index” and “follow” keys, the output in HTML is
<meta name="robots" content="max-snippet:-1, max-video-preview:-1, max-image-preview:large"/>But I wanted to completely remove the robot’s meta tag from HTML.
Hello,
Thank you for your patience.
To completely remove the ‘robots’ meta tag you can use the following filter:
add_filter( 'rank_math/frontend/robots', function( $robots ) { return []; });Hope that helps. If you have questions, please ask. We are here to help.
Unfortunately, it didn’t work.
It still outputs the following line
<meta name="robots" content="max-snippet:-1, max-video-preview:-1, max-image-preview:large"/>Hello,
The snippet is working on my setup. Screencast: https://i.rankmath.com/d47d0z
We might need to take a closer look at the settings on your website. Please edit the first post on this ticket and include your WordPress & FTP logins in the designated Sensitive Data section.
Please do take a complete backup of your website before sharing the information with us.
It is completely secure and only our support staff has access to that section. If you want, you can use the below plugin to generate a temporary login URL to your website and share that with us instead:
https://wordpress.org/plugins/temporary-login-without-password/
You can use the above plugin in conjunction with the WP Security Audit Log to monitor what changes our staff might make on your website (if any):
https://wordpress.org/plugins/wp-security-audit-log/
We really look forward to helping you.
The above filter completely removes the “robots” meta tag only when I made the following change at RankMath Settings > Tiles & Meta > Post Types > Posts > Post Advanced Robots Meta, Uncheck “Snippet“, “Image Preview“, and “View Preview“.
It is not working when “Post Advanced Robots Meta” is enabled.
Please enable “Post Advanced Robots Meta” in your setup to reproduce the issue.
Hello,
I was able to reproduce the result where I could not disable robots meta while ‘Post Advanced Robots Meta’ was enabled. Could you clarify why you want ‘Post Advanced Robots Meta’ to be enabled as having it on would be redundant while robots meta is disabled.
Looking forward to helping you.
Here is my use case.
1. I want to enable “Post Advanced Robots Meta” sitewide by default. So it will output
<meta name="robots" content="index, follow, max-image-preview:large, max-snippet:-1, max-video-preview:-1">2. But for a few pages, we want to completely remove the above ‘robots’ meta from the HTML. We’re setting the robot’s meta information via HTTP Headers using X-ROBOTS-TAG.
In our case, we must keep the “Post Advanced Robots Meta” tag enabled by default in RankMath Setting. But we have to disable it dynamically only on a few pages in order to completely remove the robot’s meta.
Is it possible?
Hello,
In short there is no simple way to disable the global ‘Post Robots Meta’ per post. You would have to build custom functions to achieve this. It might work to create a custom option that stores the IDs of the posts that you want and conditionally use the WordPress ‘pre_option’ option hook to disable ‘Post Robots Meta’.
Hope that helps.
Sounds like we’re overcomplicating things.
Why can’t we achieve this with
rank_math/frontend/robotsfilters or something similar as we are doing with Yoastadd_filter('wpseo_robots', '__return_false');Or do you have any plans to update the
rank_math/frontend/robotsfilter to support “Post Advanced Robots Meta”Hello,
The robots meta tags are an integral part of our plugin and can’t be removed completely from the HTML with any filter.
This tag is added as part of our action
rank_math/headthat is used to generate all the meta tags inside the header.The filter that you mentioned doesn’t accept boolean operands and causes a fatal error if you try to do that.
Don’t hesitate to get in touch if you have any other questions.
Now things started confusing.
Miguel says
The robots meta tags are an integral part of our plugin and can’t be removed completely from the HTML with any filter.
But Nigel has already provided the solution to remove the robot’s meta tag completely from HTML. But it only works if ‘Post Advanced Robots Meta’ is disabled.
add_filter( 'rank_math/frontend/robots', function( $robots ) { return []; });Miguel and Nigel, can you please confirm if it is possible to remove the robots tag completely from HTML with ‘Post Advanced Robots Meta’ enabled?
If it is not yet possible, I’ll stick to Yoast for now.
Hello,
My reply previously was based on the fact that you wish to keep the advanced robots meta settings.
This setting is saved inside the database under the meta key
rank_math_advanced_robotsand while that’s present the output will output its data on the page.Don’t hesitate to get in touch if you have any other questions.
My question is still not answered clearly.
“Is it possible to remove the robots tag completely from HTML with ‘Post Advanced Robots Meta’ enabled?”
Hello,
We currently do not have a way to completely remove the robots meta tag while ‘Post Advanced Robots Meta’ is enabled. It might be possible with some custom code but the customization involved is out of the scope of our support.
Hope that answers you. If you have questions, ask away.
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.
The ticket ‘How to Remove Robots Meta Tag’ is closed to new replies.