I eventually got fed up with my overuse of WordPress Template Conditional tags, and started thinking about what I could do to only use 1 Template Conditional of each type per site. It got to the point where I wasn’t sure which layouts had what code, so I started layering more code on top of existing code, which led to a bizarre patchwork of code held together by prayers and ‘if’ statements. I also ran into trouble with code repetition that is, repeating other “supporting” code, like centered divs. Other Issues with Markup-First Organization It eventually got to the point where I could no longer be sure that the code we were writing was 100% consistent and 100% reliable. This is a basic example, but imagine this organizational pattern spread across a site with 13 custom post types. Maintenance and minor updates were a challenge for other developers: changing out the section title “Events” for “Calendar” is simple, but only if you already know that header-section.php exists. This eventually led me to create themes that were organized entirely around the markup, not the layout. 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' ). 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' ). Normally, whenever I needed to change something in section header out based on the post type, I relied on Template Conditionals. The Danger of Relying on WordPress Template Conditionalsįor 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. Following the Template Hierarchy led me to a very decentralized setup, which can be inflexible and difficult to maintain. 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.įor 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-.php.
0 Comments
Leave a Reply. |