Are you a plugins addict? Don’t worry – it’s nothing to be ashamed of. We don’t judge here. As struggling plugin addicts ourselves, we understand your plight, and are here to help.
What if I were to tell you that you probably don’t need all of those plugins, and that you could decrease your site’s load time and lose no functionality? Or perhaps even increase functionality at no extra load time cost?
To good to be true? Read on.
WordPress’ Achilles Heel
As I have mentioned previously, WordPress’ enormous success is down in no small part to its staggering extensibility. At the time of writing, there are nearly twenty thousand plugins available for download from WordPress.org, with more being added every single day. It is easy to skim over that number without giving it much thought, but if you consider for a moment how big a number twenty thousand really is, the potential power you have in your hands might begin to sink in.
But with great power comes great responsibility. Plugins can be a nightmare – with everything from poor support, to security weaknesses (I’m looking at you Tim Thumb), to nasty code bloat, all waiting to trip you up.
Don’t get me wrong – I love plugins – but you should be aware of the potential ramifications. For instance, a quick scan of your site with the Plugin Performance Profiler can reveal some pretty damning results in terms of how resource-intensive your plugins are.
The Alternative
Now let’s talk about code snippets, which are lightweight, transparent, and controllable.
For those of you who don’t know, code snippets are essentially “mini-plugins” that you place in your theme’s functions.php file. What you choose to do with your functions.php file is essentially limited only by your PHP programming abilities.
Let me make something straight – there is absolutely a time and a place for plugins. Advanced functionality and extensibility should be packaged in plugin form. But for relatively straightforward tweaks and tricks, code snippets are likely to be a far more sensible option. There are probably code snippets available right now that can replace one or more of the bloated and unnecessary plugins installed on your site.
How to Get Started with Code Snippets
Even if you are a complete PHP novice, your functions.php file is unlikely to intimidate you. You can access it via FTP (you will find it in your active theme’s directory) or via the WordPress file editor (“Appearance > Editor” in the sidebar). We recommend that you access the file via FTP, because if anything goes wrong, you can easily delete whatever addition you made that caused the issue.
In its simplest form, the functions.php file looks like this:
Yours may well have more in it, but the principle remains the same – just add code snippets to the bottom of the file. It really is that simple – you can have plugin-style extensibility without putting much of a strain on your load times.
What Can You Do with Code Snippets?
The sky really is the limit. There are an enormous number of resources out there dedicated to providing popular code snippets. Here are three top sites to get you started:
And below are a selection of popular code snippets to give you an idea of what is possible:
- Track post views using post meta
- Disable Admin Bar
- Disable the Visual Editor
- Change Admin Logo
- Display Code in Posts
- Grab Tweets from Twitter Feed
- Watermark images on the fly
- Display number of Facebook fans in full text
What Code Snippets Will YOU Use?
There is no doubting the usefulness of using code snippets in adding functionality to your site whilst keeping resources required to a minimum. If you have any favorite code snippets, or have recently found one that you particularly like, please share them with us in the comments section!
Creative Commons image courtesy of fudj
Leave a Reply