Welcome to ManageWP.org

Register to share, discuss and vote for the best WordPress stories every day, find new ideas and inspiration for your business and network with other members of the WordPress community. Join the #1 WordPress news community!

×

Centralizing WordPress Code with a Theme Wrapper, Custom Actions and Layout Classes

pagely.com | Mar. 13, 2017 | 8 min read

A detailed guide to centralizing code via a theme wrapper, custom actions and layout classes in WordPress.

15 votes   Flag
Matt Cromwell

Some really good points here, but in the end it basically is suggesting to make your theme work just like Genesis. At that point I just think: Why not just use Genesis instead?

Reply
Josh Nederveld

Well, there's a lot more to my own custom theme than what's outlined here in this article. I'd say the theme wrapper, custom actions and layout classes are about 20% of it. There are a few other things I've built that give me more flexibility than any framework I've come across, while also allowing me to build sites quick. I can't speak for Genesis myself, since it's a paid thing. Do they organize the theme around layout classes as well then?

Reply
Matt Cromwell

Hi Josh, ya, pretty much all real child theme customizations are done via similar before/after hooks like you describe. And their reasoning for it is exactly the same as you describe in your article. It makes their theme very reliable overall for sure, but sometimes it makes the functions.php file really large and unwieldy.

Nevertheless, there's no doubt that hooks like this are a great way to make your theme easier to work with. It's a good write up for sure.

Reply
Josh Nederveld

Cool, cool, I wish other theme shops took this approach more often. I hate to overwrite the entire footer.php file just to change the copyright notice.

And yeah, I agree that unwieldy functions.php files should be avoided, that's why I split my themes up into one file per view, like front-page, interior, post-archive, post-singular, etc. It keeps things pretty segmented so you can just focus on what you're looking for.

The really cool thing is that filters and actions from other layouts can be removed and ADDED from a different class-- I knew they could be removed, but hadn't tried adding one until lately. Really helps me cut down on duplicate code.

Reply