Make WordPress Core

Opened 5 years ago

Last modified 21 months ago

#20037 new enhancement

Introduce 'noindex' filter for robots meta tag

Reported by: MartyThornley Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.4
Component: Themes Keywords: has-patch needs-refresh
Focuses: template Cc:


As things are right now, themes and plugins add robots meta tag lines by just adding an action to wp_head, with no way of knowing who has added what. Because it is not done as a filter, there is no way to prioritize or alter things.

As far as I can see there are two functions that are hooked to wp_head to add the meta tag for robots, the noindex() and wp_no_robots() function in '/wp-includes/general-template.php'. All noindex() does is look to see if a blog is marked private, then calls wp_no_robots(). In other places, like the signup and login pages, wp_no_robots is manually added.

To help clear up the confusion, we could just call wp_no_robots whenever we need to add a robots meta tag, use wp_no_robots to do some default logic, then allow plugins to filter it depending on where we are.

Working on a quick patch now and will add.

Attachments (2)

patch.patch (1.8 KB) - added by MartyThornley 5 years ago.
add some logic to wp_no_robots, unhook noindex from wp_head
20037_simple.patch (1.6 KB) - added by MartyThornley 5 years ago.
cleaner default meta tag

Download all attachments as: .zip

Change History (8)

5 years ago

add some logic to wp_no_robots, unhook noindex from wp_head

#1 @MartyThornley
5 years ago

  • Keywords has-patch added; needs-patch removed

To explain a few things in the first go at this...

Added some default ideas for what values should be added when. Maybe overkill or maybe not the exact right things? Not exactly a robots expert here, just wish it was more editable. :)

Needed to grab the $post so we can see where we are when filtering. As a bonus, the empty $post as it is done here, works to detect things like wp-signup.php, where wp_no_robots() has been manually added.

5 years ago

cleaner default meta tag

#2 @MartyThornley
5 years ago

After rethinking a little, came up with this simpler way of doing the default meta tag. Something like this would let core stay simple and still let everyone filter it.

Maybe even get rid of all the wp_query and idea of passing the $post, just let anything tying it to do that if they need to?

#3 @MartyThornley
5 years ago

  • Version set to 3.4

#4 @nacin
3 years ago

  • Component changed from Template to Themes
  • Focuses template added

#5 @obenland
3 years ago

wp_no_robots() is expected to output the meta tag. Changing that would likely break backwards compatibility.
Having said that, these changes could probably be made in noindex().

#6 @chriscct7
21 months ago

  • Keywords needs-refresh added
Note: See TracTickets for help on using tickets.