I am in need to remove just this line <meta name=robots content="noindex,follow"/>
from wp_head
but can’t find the right hook to use it with remove_action()
.
<meta name=robots content="noindex,follow"/>
Basically what I want to achieve is to remove just this line from the header but just for the search page. So in this case I would use something similar to:
if ( is_search() ) { remove_action('wp_head', 'whatever-the-action-name-is'); }
this should be fine i think.. somewhere in your theme functions.php and should do the trick.
Based off of your comments on my other answer implying that you explicitly wish to keep “Discourage search engines from indexing this site” enabled, after a more thorough investigation of WordPress core source (particularly default-filters.php), I think this is probably what you were after all along:
I use the
posts_selection
action hook as it’s the first hook in WordPress’s loading routine that has access to conditional tags. You can use later actions up to and includingwp_head
, but if you usewp_head
itself you need to add the action with a priority less than1
asnoindex
is added with a priority of1
:Alternately, it is possible to conditionally trick WordPress into thinking that “Discourage search engines from indexing this site” is disabled:
I got it, the output is controlled by the WordPress SEO plugin as this is enabled in the site, so I had to tiny hard code in the plugin file class-frontend.php
Obviously, I don’t like that much this dirty workaround but it works by now outputting that meta in the search page as I want.
In the class-frontend.php plugin file I had to replace the line 552 by this
I would recommend simply unchecking the “Discourage search engines from indexing this site” box from
Settings > Reading
on the dashboard (this should remove the robot-relevant meta-tags from all pages of your site), then manually adding the meta-tag back to your theme’s header using conditionals, like so:You might have to alter the conditions to achieve your desired effect, but I think you get the idea.
If you don’t care to alter your theme, you could attach it to the
wp_head
action hook:Is this what your looking for?