Make WordPress Core

Opened 15 years ago

Closed 10 years ago

#12370 closed feature request (invalid)

We need a smarter version of wp_title() and a few other template tags

Reported by: viper007bond's profile Viper007Bond Owned by: hallsofmontezuma's profile hallsofmontezuma
Milestone: Priority: normal
Severity: major Version: 3.0
Component: Themes Keywords: needs-patch
Focuses: template Cc:

Description

Look at Twenty Ten's header.php and the code that is needed to output the <title>. That's a bit silly.

I suggest we should have a helper function of some type to replace all of that. A smarter and more sophisticated version of wp_title().

Attachments (1)

12370.001.diff (12.6 KB) - added by aaroncampbell 15 years ago.

Download all attachments as: .zip

Change History (24)

#1 @nacin
15 years ago

I agree.

See also #10643, which I think should be closed as a duplicate of this one, because this ticket it seems aims to approach this from a much better perspective.

#2 @Denis-de-Bernardy
15 years ago

  • Keywords blocker added
  • Milestone changed from 3.1 to 3.0
  • Severity changed from normal to major
  • Summary changed from We need a smarter version of wp_title() to We need a smarter version of wp_title() and a few other template tags

How about porting most of the stuff in twentyten, making it the default behavior for wp_title(), and making the milestone 3.0? Also, how about porting the pagination title stuff into core?

2010 should not get released as is. As things stand, there are entire current chunks of code to work around areas where the WP template and localization APIs are dismal. Many will be laughing out loud if it gets released in the wild. I certainly will.

This theme should be an example of why the WP template engine is simple and useful. It should not be a prime example of why trying to use it is a nightmare. Marking this as a blocker.

#3 @sirzooro
15 years ago

  • Cc sirzooro added

#4 @ptahdunbar
15 years ago

  • Cc trac@… added

#5 @demetris
15 years ago

  • Cc dkikizas@… added

#6 @azizur
15 years ago

  • Cc prodevstudio+wordpress@… added

#7 @jbsil
15 years ago

  • Cc Jesse.Silverstein@… added

#8 @apeatling
15 years ago

  • Owner set to apeatling
  • Status changed from new to assigned

#9 @hallsofmontezuma
15 years ago

  • Owner changed from apeatling to hallsofmontezuma
  • Status changed from assigned to accepted

#10 @aaroncampbell
15 years ago

  • Cc aaron@… added

I did some work on this in the plane, and I'll upload a patch once I get home, but here are some thing I wanted feedback on:

  1. I added a filter (pre_wp_title) so plugins or themes can set a title and skip all the logic in wp_title(). In the case that the filter is used, should we still trigger the wp_title filter?
  2. Twenty Ten uses | as a separator (and uses doesn't look like it properly implements anything for rtl) but specifies no separator (empty string) when calling wp_title(). Do we need to build in a second separator or just use the one passed to wp_title in all places?
  3. For 404 errors, wp_title() uses the string "Page not found" which is translated. Twenty Ten however uses "Not Found" which is translated using the twentyten domain. Should we change to the TwentyTen string or use the existing one?
  4. Near the end of the current wp_title() (just before the title is split on the separator and reversed if RTL), it checks to see if $title is empty and sets $prefix. This is basically used to prepend the separator to the title (but never return JUST the separator). To keep that functionality I can just prepend the separator to the title, but that seems REALLY funny. Titles shouldn't BEGIN with a | or &raquo;. I'm all for just dropping that and using the separator to go BETWEEN things.

#11 @hallsofmontezuma
15 years ago

@aaroncampbell

I'm working on this also. Here are some of my thoughts on your comments.

  1. yes
  2. Like Denis-de-Bernardy said, 2010 should be a model, so it shouldn't have its own logic to do things that should be done by wp_title anyway. All this stuff should be stripped out. Ideally twentyten should have <title><?php wp_title(); ?></title> with everything being correctly handled by (a better) wp_title itself. Anything custom a person wants should go in a plugin.
  3. see #2
  4. We need to clean this up so that the separator should only go in between each element.

#12 @aaroncampbell
15 years ago

Sorry it took me so long to get this patch up (and it still needs better testing)...I got home and family was here waiting for us. Anyway, this patch gets rid of the leading separator, use the newer 2010 text for 404s, uses the separator throughout (but leaves the default as &raquo; not |) and adds the new pre_wp_title filter.

It converts the first argument to an args array but checks for a string and uses it as sep if needed (actually, just thinking about it I should probably have it parse args first, because args should be able to be a URL style string). We'll need to actually deprecate the second and third arguments if we do it this way. For now they're handled fine but no notice is given that they're deprecated.

This patch also changes the 2010 title tag to <title><?php wp_title( '|' ); ?></title> and gets rid of twentyten_the_page_number() in favor of get_the_page_number_title() and get_the_page_number()

#13 @sirzooro
15 years ago

Few comments:

  • I like the new pre_wp_title filter and new syntax <title><?php wp_title(); ?> - it allows plugins like Meta SEO Pack to completely takeover title generation;
  • as I mentioned earlier in #10643, plugin needs to know if this new syntax is used or not, in order to choose between old approach for title rewriting (use output buffering) and the new one; therefore templates which supports it should include call like add_theme_support( 'html-title-filter' );;
  • current version probably does not take into account custom post types - it only uses elseif ( is_single() || is_page() ); this is true for attachments too;
  • there is a typo on line 667 - is $paged, should be $page;
  • current approach does not address all cases where content can be paged. There are three cases, which needs to be handled differently: archive pages (category, author, date, ...), multi-page posts (which use the <!--nextpage--> tag) and paginated comments;
  • if it is quite easy to implement, I would like to see in title "Page 2 of 5" instead of just "Page 2". This probably needs new function, which will return total page count in all three cases listed above, or new function for each case.

#14 @sirzooro
15 years ago

One more thing: old version of wp_title() appended extra separator on left or right of the title; new version probably does not do this. We need to address this, because function should be back-compatible.

#15 @nacin
15 years ago

  • Keywords early added; blocker removed
  • Milestone changed from 3.0 to 3.1
  • Type changed from defect (bug) to feature request

Let's come to a consensus on all of this and do it right.

#16 @WraithKenny
15 years ago

  • Cc Ken@… added

#17 @aaroncampbell
14 years ago

I closed #11951 as a duplicate of this one. It's main concern was that page number be added to the title.

#18 @nacin
14 years ago

Cross referencing #13751 and [15196].

#20 @nacin
14 years ago

  • Keywords early removed
  • Milestone changed from Awaiting Triage to Future Release

#21 @scribu
13 years ago

It seems the discussion has moved to #18548.

#22 @nacin
11 years ago

  • Component changed from Template to Themes
  • Focuses template added

#23 @obenland
10 years ago

  • Milestone Future Release deleted
  • Resolution set to invalid
  • Status changed from accepted to closed

#18548 addressed finding a better way, #31078 will complete the actual implementation.

Note: See TracTickets for help on using tickets.