Use a filter for wp_title instead of hard-coding things in header.php #33

Merged
merged 0 commits into from Sep 14, 2012

Projects

None yet

5 participants

@kovshenin

Instead of hard-coding things like blog name, description and page number in the header.php template, use a simple call to wp_title() and make the rest in tweaks.php using the wp_title filter. This allows others to easily override the <title> tag without having to parse the output from buffer. SEO plugins will love this.

@obenland
Member

Related: #12

@kovshenin

Also related: #13 and #18548-core which I think will not be resolved any time soon, at least not by December 5th ;)

Sorry @obenland I wasn't smart enough to search for previous discussions about this, and your patch. The reason I put the filter into tweaks and not template tags is because it is not a template tag. It's a filter that alters the default behaviour of a core template tag, similar to how the navigation menu args are altered. We might also want to change the priority to 9 so that crappy seo plugins, that are not smart enough to filter on a later priority, could still "not break."

If #18548-core turns out into something cool, we can always adapt, plus if it does, it has to be backwards compatible, unlike us ;) In any case, this is opt-in, since tweaks.php is commented out in functions.php.

@obenland
Member

@kovshenin: For Twenty Twelve @SergeyBiryukov came up with an is_feed() check to avoid duplicate titles in feeds. See http://core.trac.wordpress.org/ticket/21233#comment:9

@kovshenin

@obenland good catch! I'd also like to emphasise one more reason why we need this before wp_title gets a complete overhaul. As per Theme Review Guidelines, themes are required to modify output via filters for wp_title and others.

@ianstewart

The patch from @azizur looks great and should go in so we can meet WPRT guidelines. I think the default value of wp_title is horrible so I'm tempted to take this out of tweaks if only so it can always be active (or just make all of tweaks active by default). How do SEO plugins generally go about overriding filtered wp_title content from random themes?

@kovshenin

Thanks for your feedback @ianstewart!

How do SEO plugins generally go about overriding filtered wp_title content from random themes?

I think most of them rely on output buffering and html parsing to enforce rewritten title tags, though some would just filter wp_title just like the above patches do, only at a lower priority. For example "WordPress SEO" does it at priority 15.

I'm tempted to take this out of tweaks.

Do you want to put it into functions.php instead? What do you think about renaming tweaks.php to something less "hackish" and including it by default from functions.php?

@ianstewart

Do you want to put it into functions.php instead? What do you think about renaming tweaks.php to something less "hackish" and including it by default from functions.php?

I like that it's modular so renaming it is cool with me rather than bloating functions.php. I'm not sure what though. Filters? Not so helpful. Enhancements?

Sorry for not @ replying you correctly. :)

@azizur
azizur commented Sep 14, 2012

@ianstewart thanks for giving the credit to @kovshenin where it belongs.

I like that it's modular so renaming it is cool with me rather than bloating functions.php. I'm not sure what though. Filters? Not so helpful. Enhancements?

How about custom-functions.php? Since that's how its currently being described in function.php

@kovshenin

How about custom-functions.php? Since that's how its currently being described in functions.php

I like the sound of it, but quite confusing, as in what's the difference between functions and custom functions :) I'm okay with custom-functions.php, however, here are a few other options to consider: additions, addons, extras, extensions, or just plain-awesome.php :D My favorite is extras, because it makes it quite obvious that they are not required and can be commented out.

Let me know which of all the options sounds best, and I'll add a commit for a rename and uncomment out the include in functions.php, so you can merge all in one go.

Thanks!

@ianstewart

Extras is the winner in my opinion.

@philiparthurmoore
Collaborator

Extras is the winner in my opinion.

+1

@kovshenin kovshenin merged commit 0b8fc2e into Automattic:master Sep 14, 2012
@kovshenin

Sorry I really suck at this GitHub thing, let's take this to #79 :)

  • Renamed tweaks to extras, included by default in functions.php
  • Using wp_title in header.php and using the wp_title filter to format it in inc/extras.php

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment