I’m a fan of using WordPress plugins because they make life easier.
I sometimes end up with the situation though where I’ve overloaded my blog. Then, I have to take drastic action.
More than likely there are WordPress code snippets I could use instead. That would remove the need for certain plugins.
Still, messing around with my blog’s inner workings isn’t something I take for granted.
Previously I had the Dynamik Website Builder installed on this blog. That made adding code snippets easy.
I found myself looking for an easy way to add WordPress code snippets without updating the child theme files.
Finding A Solution
Several plugins on the WordPress repository seemed promising. But all the ones I sourced didn’t quite fit what I was looking for.
After searching on Google, I found an article on WPBeginner about site-specific wordpress plugins.
It’s not something I’d thought about before but it makes sense for several reasons:
- You don’t have to update your WordPress core theme files;
- Your code snippets are portable between different themes;
- You won’t lose your PHP codes should your theme get updated;
- You can combine all the code snippets in one place, and;
- You might be able to get rid of some other plugins in the process.
An extra benefit is that if something goes wrong, WordPress will deactivate your plugin.
Imagine if the code you found on the web had a typo in it and you added it to your functions.php file. More than likely you’d get a white screen and be unable to access your site.
Using a site-specific plugin, on logging back into WordPress, you’d regain access.
What The Heck Is A Site-Specific WordPress Plugin?
As WPBeginner explains, it’s a place for you to add code snippets you find around the web.
You should still make any theme-specific code changes to the functions.php file. If you changed themes, some of the codes in your plugin might not be compatible. So, it’s best not to include those.
At the same time, if you’re using a framework such as Genesis, you might still consider it. Because you’re using a child theme, changing it shouldn’t cause incompatibility.
So you could add Genesis code snippets into a site-specific WordPress plugin. If you then move to a different theme or framework you would need to remove any Genesis code.
Here are some code snippets from around the web you might find useful:
- to add a custom field for sponsored posts;
- to display a custom favicon;
- to remove self-pings;
- to add disclosure text via a shortcode, and;
- to remove query strings from static resources.
Setting Up Your Own Plugin For WordPress Code Snippets
It might sound a bit daunting but setting up your own plugin isn’t too bad. Did I say easy? 🙂
Your web host can give you your login details for ftp access to your site.
There’s a few things you need to do once you’re in your site’s directory:
- Create a new folder in the plugins directory. Example: /wp-content/plugins/yoursitename-plugin/
- Open a blank file using notepad and save it as “yoursitename-plugin.php”
- Edit the file and add the following code:
<?php /* Plugin Name: Site Plugin for yoursitename.com Description: Site specific code changes for yoursitename.com */ /* Start Adding Functions Below this Line */ /* Stop Adding Functions Above this Line */ ?>
- Save the file and then upload it to the folder you created in your plugins directory.
- Then go to your WordPress Dashboard and activate the plugin.
Do You Use WordPress Code Snippets?
Some people don’t like to tinker and prefer to use a ready made plugin solution. Others are happy to get their hands dirty and customise their blogs with PHP code.
Which one are you? Do you use plugins for everything or update your theme files? What do you think of using a site-specific plugin?