How to Create a Site Specific Plugin

If you’re like many of WordPress’s intermediate users, then I’m sure that you’ve felt an urge to extend or enhance your WordPress site. Sure, there are themes and plugins that vastly improve and extend the capabilities of WordPress, but sometimes coding or adding custom functions yourself gives you a better result. Or sometimes, you want to expand those powerful themes even further by adding your own custom code to manipulate WordPress to your will.

That is the nature of WordPress – it’s hackable (in a good way). The main way to hack WordPress is to add functions and hooks which are mainly done using your theme’s functions.php file. You can directly edit it, but if your theme updates, then all of your edits in the functions.php file will be lost – so the solution? Create a child theme. But what if you want to edit functions that aren’t dependent on your theme? Sure, you can still add them to your child theme, but it’s better to create a site-specific plugin for that. This way, if you ever change a theme, then you don’t have to reapply the theme independent custom functions that you added.

Creating a Site-Specific Plugin for Your WordPress Site

Open your favorite FTP client and connect to your WordPress site. Once you are connected, open your WordPress plugins folder. Inside the folder, create a new folder called site-plugin and inside it, create a new file called site-plugin.php, you can actually name them anything you want, however, so feel free to do so. What’s important is that we create a new folder inside WordPress’s plugin folder and inside that folder, we create a new PHP file that will hold our custom snippets.

Now that you have the PHP file ready, copy the code below and paste it into your PHP file:

<?php
/*
Plugin Name: WHATEVER NAME YOU WANT
Description: Site-specific code changes for example.com
*/

/* Start Adding Functions Below this Line */

/* Stop Adding Functions Below this Line */
?>

You can change the plugin name to whatever you want, perhaps something like “Site Specific Plugin for EXAMPLE.COM” or something. The plugin name and description you put in there will be displayed in your plugins page. Don’t worry, it’s just for aesthetic and won’t impact your site in any way.

Save the file and log in to your WordPress dashboard. Check out the plugins page and you’ll see your new plugin there. Activate it and you’re done! That’s it!

Now, if you found a code snippet online that you want to try on your site, or if you have code snippets now that you want to add, simply open your site-specific plugin PHP file again (pro tip: you can also do it inside your WordPress dashboard, just click the edit button under your plugin name) and paste the code snippet inside after and/or before the lines that say start and stop adding functions. Save your file once you added your code snippet and you’re done!

You can change the plugin name to whatever you want, perhaps something like “Site Specific Plugin for EXAMPLE.COM” or something. The plugin name and description you put in there will be displayed in your plugins page. Don’t worry, it’s just for aesthetic and won’t impact your site in any way.

Save the file and log in to your WordPress dashboard. Check out the plugins page and you’ll see your new plugin there. Activate it and you’re done! That’s it!

Now, if you found a code snippet online that you want to try on your site, or if you have code snippets now that you want to add, simply open your site-specific plugin PHP file again (pro tip: you can also do it inside your WordPress dashboard, just click the edit button under your plugin name) and paste the code snippet inside after and/or before the lines that say start and stop adding functions. Save your file once you added your code snippet and you’re done!

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright MBP Ninja Affiliate 2017
Tech Nerd theme designed by Siteturner