By fully embracing the DRY principle in our WordPress builds, we are able to write more efficient code and create more flexible websites. Traditionally, when developing a site, the focus is on page templates. Whether it’s a template for your home page, about page, or an archive, your content may change, but there is usually a pre-defined structure. We look a little deeper and focus on the unique, self contained sections of a page, otherwise known as modules.
Here’s an example. Say you have a page with a video, some text and a gallery. Rather than create a single template for a “Video and Text and Gallery” page type, we create three modules. A video module, a text module, and a gallery module. Then, when the time comes to build another page which has text, video, and a slideshow, we already have 2 of the modules built. And let’s say, down the road the client would like to update the controls for all videos across the site. Rather than finding every page template with a video in it and updating your markup, you just edit your one video module, and every page that uses this module is updated.
Using Advanced Custom Fields’ repeater option, these modules can be added to any page on a site. This really comes in handy if you want to create a new page on the fly. You can mix and match any of the existing modules to create a completely unique page, all without updating a line of code!
The modular setup makes it easy to build and update custom pages within the WordPress admin, but it also makes development incredibly efficient. It starts with a basic page template, which loops through each module added to that page within the admin. Then, each module’s template is included on the page. We’ve also bundled each module’s styles and script along with the template, which means it’s very easy to troubleshoot or debug because each module’s code is self contained.
This approach has increased our efficiency and allows us to give our clients powerful, versatile platforms with the ability to grow.