It’s the New Year, a traditional time for resolving to make changes in our lives to better ourselves in the coming 12 months (and hopefully beyond).
Even though many of us stop going to the gym in about mid-February, there’s smaller changes that you can make in your life that are more manageable and realistic. Given that this blog is all about WordPress, it only seems fitting to write down a few “best practices” that you should try and adopt in order to make editing, managing and updating your blog a whole lot easier.
Stop using functions.php
It’s something that I mention frequently, but if ever you needed a kick up the bum to do this, now is the time. functions.php should be a file that is used by theme developers to define functions that manage and alter the way in which the theme appears and operates.
When we want to add or modify some functionality in our blog, we are often presented with snippets, which many people will tell you to put into functions.php, a habit which I want to help stop. This isn’t good because if you change or update your theme, any snippets you entered into functions.php will not be reflected in your new theme.
The better way to handle adding these code snippets is to use a functionality plugin. Do not be alarmed or overwhelmed; it’s actually very easy to create and you’ll be underway in about 10 minutes. Make the change now!
Edit theme and plugin files more appropriately
Once you start getting your feet wet in WordPress, you might start looking at your theme/plugin files and consider editing them to alter the appearance of your site slightly, whether it’s to add some social sharing buttons, or to add featured images to your posts.
There’s just a few tips that you should try and take on board which will help with managing your blog and keeping track of your edits:
Use comments to remove portions
Never, ever, ever delete code from a theme file or plugin file. Instead, use comments; this is a way of basically saying “ignore this bit”. If you’re editing a PHP file, you can comment out a section by using /* and */ to denote the beginning and end of your commented section. So for example, in the following section of code from my own functionality plugin, the snippet for delaying publishing to my RSS feed is disabled:
Make notes and explain your code
You should also use comments to make notes in your code on what each line does, or on what each section of code is for. In the example above, you’ll see that there’s a comment before each of the snippets that specifies what each snippet is for, for easy reference when looking at the code in future.
If you’re a theme or plugin developer, you should also use comments to explain your code, so that anyone (including yourself) looking at the code in future to either understand or modify it, can see what everything does. As an example, the following is a section of code from my SOUP widget, which shows upcoming posts to your readers:
As you can see, each line has an inline comment (marked by two slashes followed by the comment) explaining what it means, for easy reference during development and also for future modifications.
Your own resolutions?
What resolutions have you made for running/editing your WordPress sites over the next year? What would you tell others to do?