Over the years, I've found myself in the functions.php file, creating custom shortcodes or snippets…
The best part about WordPress is probably the fact that everybody can use it to create an amazing website for their or their clients’ business. It doesn’t really matter if you have ages of experience coding, or you are an absolute beginner. With WordPress, you can still have your site the way you like it and with all the functionalities you could look for in a website.
Whether one solution is better than the other is a debate we won’t get into: we would like to present the middle-ground instead. When you need the functionality of a plugin, but you are not looking to install another one, you can use snippets.
The beginners might ask here: What is a snippet? A snippet is, basically, a short PHP code that can help you get additional functionality on your site without actually installing a plugin.
Why are snippets useful?
You could go ahead and install a plugin, of course. Still, at some point, you might realize that you have one too many. How will you know its too many plugins? Your site will start to misbehave, become slow, or even worse, experience downtime. Not to mention that if you have some old or outdated plugins installed, your site could easily get hacked.
With code snippets, you can get the functionality you need, without having to install a plugin or two. This brings a couple of positives – it won’t slow down your site, and you are pretty much safe in this regard when it comes to hackers.
On another note, developers oftentimes rely on snippets to be as lazy as possible. Why? Well, why would they type the code if they can simply copy-paste it? Avoiding repetitive work is not a privilege reserved for non-developers.
In essence, when it comes to WordPress, code snippets should be pasted in your site’s theme’s functions.php file to add the needed functionalities. Paste one snippet, then another, and then another, and you will soon see a mess, similar to the one you might have created on your plugins overview. So, what is there to do?
Well, you can always go for a plugin (yes, for handling your snippets!) There is this amazing little plugin called Code Snippets, that can help you organize, manage, and get the most out of your snippets.
What are the features of Code Snippets?
As mentioned before, the Code Snippets plugin can help you manage, create, import, and delete snippets from your site as effortlessly as possible. Let’s check out how.
The first thing you will notice if you decide to go with this plugin is the amazing overview of the snippets. Similar looking to plugin overview, to ensure that you are comfortable with the format, you can effortlessly add a new one, or find the snippet you are looking for so that you can edit it, clone it, export or delete it if you don’t need it anymore.
Overall, through this preview, activating or disabling a snippet is a piece of cake, as all you have to do is use the toggle option. You can set up a customized description to be able to differentiate them, and so that you can get to know what a particular snippet does in a single glance.
Tags are the first line of defense when it comes to preventing the mess from appearing anywhere when it comes to WordPress. The same goes for your snippets, so you should take advantage of the tags feature of the Code Snippets plugin!
Code Snippets plugin comes with a fully functional code editor so that you can effortlessly add new, or edit existing snippets on your site. After typing in (or pasting, we’re not judging) your new snippet, you can further select how you would like to run it.
You can choose to run snippet only in the administration area, or only on the front end. Of course, you can run the snippet anywhere, or, you can set it up to run only once, on a special occasion.
From here, after you add needed description and tags, you get to decide if you would like just to save it, or to activate it, too. The plugin will do the rest!
Just because you have created it in the Code Snippet’s editor, it doesn’t mean it has to stay there, too. If you need your code snippet, all you should do is export it. It will do so in PHP so that you can use it later for developing another theme!
While installing a plugin to handle snippets you would like to use instead of a plugin might seem like a catch 22 at first, installing Code Snippets is far from being a bad idea. After all, with all the snippets neatly organized, easy to activate, use and edit, you can take advantage of this plugin’s help to get rid of some other plugins which you could replace with snippets. Who’s to say no to a free, straightforward plugin that can help you do more with your site?