Standardising WordPress theme hooks
I’ve been working on integrating our SEO plugins more deeply with Genesis the last few weeks and something dawned on me. Ever since I wrote my post on Genesis 2.0, I’ve been thinking: Genesis started a small revolution, but we should open that up. More theme developers should start doing a Schema.org API and if they do, we should make sure they’re interoperable.
In short: Genesis 2.0 added a Schema.org API, with hooks like:
- genesis_attr_entry
- genesis_attr_entry-title
- genesis_attr_entry-content
These hooks are very consistently named, which is very important. There’s one “issue” though: they’re namespaced. They all start with “genesis_”, which is a good practice by the Genesis community and one most theme authors use. But let’s think about this from a plugin authors perspective: if I add support for Genesis Schema.org API and say WooThemes decides to adopt it as well but prefixes it with “woo_”. And then 10 other theme vendors do the same thing. Instead of having one line of code that filters a specific hook’s output, I have 10 add_filter lines to add, and I need to do that for every change.
The same is true with some other hooks that loads of us plugin developers need but WordPress core refuses to add. I’ve had lengthy discussions about the need for a body_open hook in core, but the core team has all sorts of reasons not to want that. I see why, but that doesn’t stop us, as the WordPress community, with coming up with our own standards for hooks and standardizing them in a proper fashion.
WordPress theme hook standardisation board
I think we should be able to get the big theme guys together and come up with a proper standard for these things and it wouldn’t even need much work. Because genesis naming is so elegant, everyone could copy their schema.org API and prefix it with their own standard prefix. The only thing we have to decide on together is a constant we define for the theme prefix.
I’d say WP_THEME_NAMESPACE would be good. What that would allow is for Genesis to define that constant as “genesis”, and for me as a plugin author to hook into that:
[code lang=”php”]add_filter( WP_THEME_NAMESPACE . ‘_attr_entry’, ‘yoast_filter_function’ );[/code]
This would then work with every theme that has support for that API and has defined the theme’s namespace. For other hooks it might be a bit more work, what I’d call “body_open” is in Genesis as “genesis_before”, which is semantically a bit weird in my opinion, but we should discuss.
I’d love to come up with a proper standard for these things. Which is why I’m calling for the formation of a WordPress theme hook standardisation “board”. I’d love to standardise hooks that all big themes have in such a way that plugins can start to rely on them. We shouldn’t “rely” on the core team to do this, in my opinion. I’d love to get StudioPress, WooThemes and all of the other theme people on board and do this together. If you represent a theme company and would like to join, jump in in the comments and I’ll contact those of you who “register” their support to come up with a proper way of discussing this.
Update: of course 10 seconds after publication @nacin tells me something like this already exists in part: the Theme Hook Alliance. We should probably all work together :)
Coming up next!
-
Event
International Search Summit 2024
November 14, 2024 Team Yoast is at Attending, Speaking International Search Summit 2024! Click through to see who will be there, what we will do, and more! See where you can find us next » -
SEO webinar
Webinar: How to start with SEO (November 19, 2024)
19 November 2024 Learn how to start your SEO journey the right way with our free webinar. Get practical tips and answers to all your questions in the live Q&A! All Yoast SEO webinars »
16 Responses to Standardising WordPress theme hooks