Monday, 13 March 2017

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


I’ve been developing WordPress themes and plugins for the past 6 years, and in that time, I’ve learned a lot about how to efficiently centralize and organize WordPress theme files. For a long time, I thought that using Template Files was the right way to organize my WordPress theme– just whip up a post-type-specific template-file, like archive-{post_type}.php. Following the Template Hierarchy led me to a very decentralized setup, which can be inflexible and difficult to maintain.
The Danger of Relying on WordPress Template Conditionals
For example, on just about every project I have a file called header-section.php, where I put a section title, breadcrumbs, and maybe a background photo.
Normally, whenever I needed to change something in section header out based on the post type, I relied on Template Conditionals.
So if I wanted to change out the section title on the events archive, I’d write a template conditional like is_post_type_archive( ‘events’ ) . But if I’ve got a taxonomy archive for events too, I’d have to couple that on there as well, like this: is_post_type_archive( ‘event’ ) || is_tax( ‘event-category’
Source: https://managewp.org/articles/14573/centralizing-wordpress-code-with-a-theme-wrapper-custom-actions-and-layout-classes




source https://williechiu40.wordpress.com/2017/03/13/centralizing-wordpress-code-with-a-theme-wrapper-custom-actions-and-layout-classes/

No comments:

Post a Comment