WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 3 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
Focuses: template Cc:

Description

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 2 years ago.
add some logic to wp_no_robots, unhook noindex from wp_head
20037_simple.patch (1.6 KB) - added by MartyThornley 2 years ago.
cleaner default meta tag

Download all attachments as: .zip

Change History (6)

MartyThornley2 years ago

add some logic to wp_no_robots, unhook noindex from wp_head

comment:1 MartyThornley2 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.

MartyThornley2 years ago

cleaner default meta tag

comment:2 MartyThornley2 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?

comment:3 MartyThornley2 years ago

  • Version set to 3.4

comment:4 nacin3 months ago

  • Component changed from Template to Themes
  • Focuses template added
Note: See TracTickets for help on using tickets.