In the various WordPress tutorials you will find around the web (and even on this site), many times you will be told to put certain code in your theme’s functions.php file. While this method of adding new features to your site will technically work, it also can be somewhat problematic. A site specific WordPress plugin on the other hand is a much better way to add new features and functionality to your WordPress site without having to touch your theme’s files. Here’s why.
When you update a core theme file such as the functions.php file, you are modifying a file that could get overwritten, or become completely obsolete in the future.
Think about it this way when you add a bit of code to functions.php, you are saving your version to your server so your site can use it. When the theme your site uses gets updated, a new clean version of functions.php is included and will not include any of the custom code that you included in your version.
Why Not Use a Child Theme?
Some people recommend using a child theme so that the parent theme’s functions.php file isn’t modified, and changes won’t be lost in future updates.
While this will work fine in most cases, it still can be problematic.
Recently an e-commerce site I worked with had a few key functions related to the e-commerce portion of their site in their theme’s functions.php file. When the site was redesigned with a new theme, all of those critical functions were not carried over to the new theme so the e-commerce functionality was not operational at all until the code was put back in action.
After that issue, we created a site specific WordPress plugin so the changes will never be lost again.
Granted, theme changes like this are probably not very frequent. But it still creates an additional step to take when changing themes, and is easy to forget to do.
Use Site Specific WordPress Plugin
Using a site specific WordPress plugin is much easier to manage. You can update your site’s theme, or change it entirely and you will never lose the functionality contained in the site specific plugin.
Some people might be intimidated by the idea of creating a plugin on their own, but there really isn’t anything to be worried about. Here are the steps to creating your very own site specific plugin. There’s a sample site specific plugin ZIP file download at the end of this article.
First, you will need to access your site through an FTP program like FileZilla. If you are unsure how to connect to your site by FTP, contact your web host for more information.
Next, navigate to your /wp-content/plugins directory, and create a new directory. You can call it whatever you want /wp-content/plugins/site-specific-plugin would work though.
Create a new PHP file inside the new site-specific-plugin directory. You can call this whatever you want as well, but for the guided tour /wp-content/plugins/site-specific-plugin/site-specific-plugin.php will work.
In the new site-specific-plugin.php file, put the following code:
/* Plugin Name: Site Specific WordPress Plugin for example.com Description: Site specific plugin for example.com */
You can change example.com to your domain if you want. Actually, you can change anything after “Plugin Name:” and “Description:” to suit your needs. Also, be sure to start and end your PHP file with
Right now you have a valid plugin, but it won’t do anything other than add another row to your site’s list of installed plugins after it is activated.
To add some functionality to the plugin, open up your existing theme’s functions.php, and copy the code that you added for a certain function. Return to your site-specific-plugin.php file, and paste that custom code after the
In your WordPress admin dashboard, navigate to Plugins > Installed Plugins.
Find your new site specific WordPress plugin in the list, and click activate. If you have done everything correctly, the plugin should activate successfully and the functions you added to it will be working on your site.
The next time you come across any code changes that recommend adding the code to your theme’s functions.php file, add it to your site specific WordPress plugin instead.
You can download a sample site-specific plugin here. Upload this to your site by navigating to Plugins > Add New > Upload Plugin.