My six or so years of developing WordPress themes and plugins have given me perspective. I’ve had enough time to realize what I should have done differently when I was getting ramped up, and what I’ve learned just by fumbling through. Through the years, I’ve also seen countless people start learning to code by tweaking WordPress themes, and witnessed developers of other languages getting their hands dirty with plugins.
So, let me save you some heartache. There are some “best practices” that are better followed from day one, instead of trying to integrate them into your workflow later.
Before you touch a line of code in a WordPress environment, you must know when and how to create child themes and plugins. If you don’t, you’ll end up fixing your mistakes later.
Never Edit Code in an Existing Parent Theme
If you want to change something in a theme, and it’s not a change you can make happen with an existing setting, there’s a simple answer: use a child theme.
Child themes provide several benefits. One major benefit is that it leaves the parent theme able to be updated in the future. For example, let’s say a theme you were using included a script to create thumbnails that had a major vulnerability exposed. The original theme author can push an update to the theme, and you can update the parent theme directly, instead of having to go back and try to remember what you’ve changed. It takes way more time to go back, find those changes, update the theme, and recode the changes, than it does to do it right the first time.
I speak from experience. I’ve done it the wrong way. And every time I’ve needed to update a parent theme, it’s taken way longer than it would have if I just did it right.
If you want to avoid wasting your time like this, don’t edit code in an existing, non-child theme unless you built it yourself. Never touch that code.
Are you new to the concept of creating a child theme? Just search around or start with the Codex. It’ll be overwhelming for the first 30 minutes, but after that you’ll quickly begin to understand. And those few hours you spend learning the fundamentals will pay off in ways you’ll never even realize.
With Genesis (and similar themes), you have a slightly different setup to which you can apply the same principles. Instead of creating a child theme, you’re already using a child theme that’s built on top of the parent theme (sometimes called a “framework”), and you make changes using “hooks” (actions and filters).
Do your research on the parent theme, and you’ll be good to go!
Build a Plugin for Non-Design Functionality
When you want to tweak or add functionality to your existing parent theme (that won’t be missed if the themes change later), use a child theme. A great example of this would be integrating a custom web font. Since typefaces are usually tied to a design, you can integrate this into a child theme.
However, if you want to create a new post type, and you want that content to stick around when the theme changes, build a plugin. No exceptions.
Similar to child themes, you’ll need to spend some time learning how to build a plugin, but don’t worry it will definitely be worth it! Dive in and do it the right way, instead of taking the “easy way” out and putting a code snippet into your functions.php file.
Work with Plugins like a Pro
In some cases, you can build off existing plugins and tweak their functionality by understanding the principles of child theming and plugin building. For instance, you can use powerful premium plugins and utilize their “hooks” and functions to save yourself time. Plugins, like Gravity Forms and Easy Digital Downloads, come equipped with API’s. Work with them! Apply the same principles whether the code functioning with the plugin goes into your child theme or another plugin.
You can also make plugins that extend other plugins, which makes your code much more future proof.
If you ever need to tweak a plugin you didn’t build, but you want to maintain the ability to update that plugin later, here’s an advanced tip: use revision control branching. This is the best method I know for keeping that plugin ‘upgradable’ in the future, without having to scramble and remember what you changed.
Skip Learning “The Hard Way”
It’s my hope that you never have to fully understand just how important these “best practices” are because you will implement them from the very beginning. Remember to:
1) Always use a child theme to tweak things in the code
2) Always build a plugin for functionality that needs to stick around after the theme is gone
3) Understand and use “hooks” in some theme frameworks and plugins to extend great code
Try these tips out for yourself, and share your experiences in the comments below!
Cliff Seal is a UX Designer at Pardot, a salesforce.com Company—a leader in B2B marketing automation — where he is the resident WordPress developer and has co-led team efforts on a complete Pardot.com refresh and a major UI overhaul. Cliff has been developing in WordPress for over five years as Logos Creative, and also co-founded MusicGrid.me.
No Comments