[wp-trac] [WordPress Trac] #18548: Add a better option for <title> tags

WordPress Trac wp-trac at lists.automattic.com
Wed Aug 31 13:14:42 UTC 2011


#18548: Add a better option for <title> tags
------------------------------------------------+--------------------------
 Reporter:  joostdevalk                         |       Owner:  joostdevalk
     Type:  enhancement                         |      Status:  new
 Priority:  normal                              |   Milestone:  Awaiting
Component:  Template                            |  Review
 Severity:  normal                              |     Version:  3.3
 Keywords:  has-patch dev-feedback needs-codex  |  Resolution:
------------------------------------------------+--------------------------

Comment (by nacin):

 wp_title_tag() does indeed solve one problem by including <title> tags in
 its output.

 Unfortunately, it's inherently less flexible, so it's not really going to
 convince anyone to use it. It also requires a function call, so it's not
 backwards compatible out of the box. And, since it doesn't require support
 registrations, it's not forwards compatible either, with stuff we may (and
 want to) do in the admin.

 When talking with Joost I proposed a way to handle the issues raised here
 very elegantly. Essentially, we could prevent our new title tag from being
 rendered if wp_title() has already been called. At the time, we dismissed
 it as silly for anyone to do this, as they'd instantly see the mistake.
 However, greenshady brings up an excellent point about child themes. So
 let's move forward with the idea.

 The attached patch:

  * Requires that add_theme_support('title-tag') is fired on the
 after_setup_theme or init hooks, or in the body of functions.php. By doing
 this, it requires that support can be discerned in the admin for a
 possible future feature. This is enforced using doing_action(), which was
 proposed in #14994. (This patch is designed to work without applying that
 patch, however.) I really like this, and I think that add_theme_support()
 should have this kind of enforcement for all kinds of theme support.

  * Prevents a title tag from being rendered if wp_title() has already been
 called, by checking to see if the wp_title hook has already been fired.

  * Requires that _wp_render_title_tag() is only called internally on the
 wp_head hook. This enforces it as an internal hook callback rather than
 the potential it gets used as a title tag.

  * Adds a new return value for add_theme_support() of WP_Error.

  * Removes the `false` return from the pre_wp_title_tag hook. The only way
 to bail is to provide a title to be printed. Continues to treat
 pre_wp_title_tag as a short-circuit filter that bails immediately, in line
 with many other pre hooks in WordPress.

 Remember, requires #14994 for most of this.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18548#comment:37>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list