Do you want to add a site-specific plugin to your WordPress website?
A site-specific plugin allows you to easily add code snippets to your WordPress website without relying on your theme.
In this article, we will explain how to create a site-specific WordPress plugin and why it’s important.
What Is a Site-Specific WordPress Plugin?
A site-specific WordPress plugin is a standalone plugin that you can use to add all customization snippets that are not theme dependent.
When working on your website, you will often find WordPress tutorials asking you to add code to your theme’s functions.php file or a site-specific plugin.
WordPress doesn’t come with a site-specific plugin. You will need to create your own and then install and activate it.
Why Create a Site-Specific WordPress Plugin?
As we mentioned earlier, you will often come across tutorials showing some code that you can add to your theme’s functions.php file or a site-specific plugin.
These custom codes can be used to add new post types, taxonomies, shortcodes, and tons of hacks to improve your website.
If you add the custom code to your theme’s functions file, then it will disappear if you update or switch your theme.
You can create a child theme and use the child theme’s functions file to save your code. However, your code will still disappear if you switch themes.
A site-specific WordPress plugin allows you to easily add custom code snippets to your WordPress website and make sure they are theme-independent. It is a standalone WordPress plugin, which means it doesn’t depend on your theme, and you are free to update or switch your theme.
That being said, let’s take a look at how to easily add custom code using a site-specific plugin. We will show you two ways to do that, and you can choose the method that works best for you (hint: Method #2 is easier for beginners).
Method 1: Manually Create a Site-Specific WordPress Plugin
We know this may sound a bit geeky to beginners, but we will try to make it as simple as possible for you.
First, you need to create a new folder on your desktop and name it after your website. For example: mywebsite-plugin.
Now, open a plain text editor on your computer like Notepad or TextEdit.
You need to create a new file and save it as mywebsite-plugin.php in the plugin folder on your desktop.
Your plugin file needs a specific header code so that WordPress can recognize it as a plugin. Go ahead and add the following code to your mywebsite-plugin.php file:
<?php
/*
Plugin Name: Site Plugin for example.com
Description: Site specific code changes for example.com
*/
/* Start Adding Functions Below this Line */
/* Stop Adding Functions Below this Line */
?>
You can replace example.com with your own domain name. Once you do that, your site-specific plugin is ready.
There are two ways to upload your site-specific plugin to your website. You can either upload it via your WordPress admin panel or use FTP.
1. Install Site-Specific Plugin From WordPress Admin Area (Recommended)
This method is easier and recommended for all users.
First, you need to create a zip file of your site-specific plugin folder.
Windows users can simply right-click on the plugin folder and select Send to » Compressed (zip) folder.
Mac users need to right-click.
Then, select “Compress mywebsite-plugin”.
Once you have the plugin’s zip file, go to the Plugins » Add New page in your WordPress admin area.
Then click on the ‘Upload Plugin’ button on the top.
Next, click on the ‘Choose File’ button to select the zip file you created earlier, and then click on the ‘Install Now’ button.
WordPress will now upload and install the plugin for you. Once it’s uploaded, you need to click on the ‘Activate Plugin’ button to start using your site-specific plugin.
2. Upload Your Site-Specific WordPress Plugin via FTP
For this method, you don’t need to create a zip file. You will be uploading the plugin via FTP.
First, you will need to connect to your website using an FTP client.
Once connected, go to /wp-content/plugins/ folder under the remote site column. Next, you need to select your site-specific plugin folder and upload it to your website.
Your FTP client will now transfer your site-specific plugin folder to your WordPress website. This will install the plugin on your website.
However, you will still need to activate the plugin to start using it. You can do this by going to the ‘Plugins’ page inside your WordPress admin area and then clicking on the ‘Activate’ link below your site-specific plugin.
That’s all. Your site-specific plugin is now ready to be used.
Adding Custom Code Snippets to Your Site-Specific Plugin
There are two ways to edit your plugin and add custom code snippets to it.
The first method is to do it via the WordPress admin area. You can go to the Plugins » Editor page.
You will see a warning message, and you need to click on the ‘I understand’ button to continue. Alternatively, if you want a safer way to edit the files, then skip to the second method below.
Next, you need to select your site-specific plugin from the drop-down menu labeled ‘Select plugin to edit.’
The editor will load your plugin file, and you will be able to add code snippets to it.
Once you are done, click the ‘Update File’ button to save your changes.
If there is something missing in your code or it has the potential to break your website, then the plugin editor will automatically undo your changes.
However, if the editor fails, and you see the white screen of death, then you can use FTP to edit your plugin file and undo those changes.
The second method is to directly edit the plugin file using FTP. Simply go to the plugin folder using your FTP client. Right-click on the plugin file and then select ‘View/Edit’.
You can also download the plugin file to your computer, edit it, and then upload it back.
Method 2: Adding Custom Code Using WPCode (Recommended)
This method is a lot simpler and gives you a better way to manage your individual code snippets in WordPress using WPCode.
The first thing you need to do is install and activate the free WPCode plugin on your website. For more details, see our step-by-step guide on how to install a WordPress plugin.
Upon activation, the plugin will add a new menu item labeled ‘Code Snippets’ to your WordPress admin menu. Clicking on it will bring you to a page where you can manage all your custom codes.
To add your first code snippet, click the ‘Add New’ button.
This will bring you to the ‘Add Snippet’ page. Here, you can choose a code snippet from the pre-made library or add your custom code.
To add custom code, navigate to the ‘Add Your Custom Code (New Snippet)’ option and click the ‘Use snippet’ button.
Now, you can enter a title for your custom code snippet. This could be anything that helps you identify the code.
After that, you can go ahead and paste your code snippet into the code box. You also need to select the ‘PHP Snippet’ type from the ‘Code Type’ dropdown list on the right.
You can also add notes for the code in the ‘Basic info’ section.
You should use this area to write down what this code does, where you found it, and why you are adding it to your website. This will help the “future you” remember why the “past you” added this code.
You also have the option to assign tags to your code snippets, which can help organize code snippets by topic and functionality.
The plugin also allows you to select how you want to run the code snippet. In the ‘Insertion’ section, you can select the ‘Auto Insert’ method to automatically insert and execute the code on your site.
You can choose from the admin area, front-end, or everywhere options. If you are unsure, then keep the default ‘Run Everywhere’ option.
Or, you can choose the ‘Shortcode’ method. With this method, the snippet is not automatically inserted. Once you save the snippet, you will get a shortcode that you can manually insert anywhere on your site.
You can also use the ‘Smart Conditional Logic’ section to either show or hide auto-inserted snippets based on a set of rules.
For example, you can load code snippets for logged-in users only, load PHP code snippets only on specific page URLs, show code snippets based on the type of page, and more.
Finally, you can toggle the switch from ‘Inactive’ to ‘Active’ and then click on the ‘Save Snippet’ button.
If you want to save the code snippet without activating it, then you can click on the ‘Save Snippet’ button only.
Once you have saved and activated a code snippet, it will become automatically effective on your website if that’s the insertion method you chose.
For more details, see our guide on how to easily add custom code snippets in WordPress.
We hope this article helped you learn why and how to create a site-specific WordPress plugin. You may also want to see our list of useful functions file tips and the most wanted WordPress hacks to best use your site-specific plugin.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
BSubra
Is it possible to add code snippets like Google Analytics Code, Adsense code in Site Specific Pliugin. Or only possible to add codes we generally put in functions.php file.
I mean, is it possible to add codes in site-specific plugin what we generally put in Header.php file.
WPBeginner Support
You can do that if you would like, you can also use the insert headers and footers plugin.
Admin
Bola Oussou
hi
Thanks for this tuto
however is there a way to make this plugging(not to be visible) not in plugging list and also in a specific folder (not wp-content folder) ?
Thanls
Tor-Bjorn Fjellner
Actually yes, there is:
Instead of placing the plugin in …/wp-content/plugins/ you put it in …/wp-content/mu-plugins/ (You may have to create that directory, if it’s not there yet.
Plugins that are placed in mu-plugins are ALWAYS run, so the only way to deactivate a MU plugin (MU currently is construed as “must use”) is to delete it (or remain the directly mu-plugins to something else…).
Judith
Hi I tried to do the Site-specific plugin, but it is not working, I get this message “The package could not be installed. No valid plugins were found.
Plugin installation failed.”
What do I do?
WPBeginner Support
Hi Judith,
This usually means that the plugin header information is incorrect. You can try again and make sure that your plugin header is exactly in the format displayed in the tutorial.
Admin
Jonathan Manheim
I get this same error. I have tried maybe 10 times. Uploaded through admin and on FTP. Cannot get it to upload. I am using TextEditor to paste the code. Notice several things you don’t mention in the post that I wonder could be an issue. First, won’t let me save the file as .php. I have to save it as .php.rtf OR .rtf then go back and rename the file after it is saved.
Second, not sure what you mean by making sure the format for the plugin header is exactly the same. Should the line number be in there? If so, I can’t get that to work. If I copy and paste with the line numbers, the green vertical line doesn’t show up and there is no space between the line numbers and the code. Or am I supposed to just copy the code (without the line numbers)? Either way, I’ve tried everything I can with my current Textedit application and it will not work.
Any ideas? I can send you screen shots of exactly what I have if you would like
WPBeginner Support
Hi Jonathan,
You will need to save file as .php. Please use a different text editor on Windows you can use Notepad or download Notepad++. On Mac, you can use TextEdit or download and install TextWrangler.
You don’t need to copy and paste line numbers.
Kacper
In my case the issue was that the file had Unicode encoding. Changing it to ANSI fixed the issue.
Ikram
Hi,
Good day!
Would like to know how to set a white paper in my blog post article to download it with add email address from the visitor.
Thanks, Ikram
WPBeginner Support
Hi Ikram,
You can do that with the pro version of WPForms. You will need at least Plus plan for that. After users enter their email address and click submit you can redirect them to the download page.
Admin
Alain Fradette
Great info! Thanks so much. I have been using WordPress for years and this little gem made it so much easier!
Abhijeet
I have edited some code in Style.css . Will it be overwritten if i update a theme?
is it possible to create style css file in this site specific plugin?
LFreitas
Yes, they will.
You should create a child theme and put your modifications there instead of in the original theme.
Read more: https://www.wpbeginner.com/glossary/child-theme/
dave
White screen on publishing pages.
The code works to show child pages on a parent page using the shortcode however I am getting white screen. Anyone know why?
Tommy
The plugin generated 3 characters of unexpected output during activation. If you notice “headers already sent” messages, problems with syndication feeds or other issues, try deactivating or removing this plugin.
Saurin
I believe best approach to add custom code to site is child theme. No matter if we need to customize theme or not. I mad a practice to always use child theme even if there is no customization. This habit saved my time & effort many times. I dont think it is good to create extra plugin for such customization.
I believe in minimum use of plugin no matter how simple you created one.
Jason
Which is better, site-specific plugin or Child Theme? or both?
I need to create a custom post type to add some major functionality to my site so is the plugin better or the child theme and its functions.php?
Thanks!
Josh
The thing is, is that you’re creating the plug-in yourself, using the functions the same exact way. So the answer to your question would be that neither is better, because you should be using them WITH each other.
Josh
Think of the site-specific plug-ins as functions that are independent of your theme.
Vickey
How would I create a create a new plugin directory in Azure? I have Wordpress running on Azure using MS SQL Server, which I activated using Project NAMI.
vishal
not working on multisite with publisher theme can you help me this is my site and also tell me how can i remove featured image inside the post not from front page latest post
Nadia Khan
Hi there,
You WP Beginners are rock. and I want to thank you for your Struggles for us.
Now come to the point. I have installed an theme and in that theme, there is an function that is showing wp toolbar for guests, I have tried so many times to find this function in theme files to remove this, but i can’t. So please help me to remove that toolbar, that is showing to every visitor with wordpress logo and wordpress’s own link to their website. Screen Shot is attached.
Manuel
Does something like this work for plugins too? Im finding that I am making a few changes to plugins that I add to my site….many times deleting certain lines of code I dont want. I’m assuming that after I update that plugin, all my changes will be erased. How can I avoid this?
Elizabeth
Hi, thanks for the post. I’m getting an error when I activate the plugin for some reason:
Parse error: syntax error, unexpected ‘*’, expecting identifier (T_STRING) on line 9
Any ideas what I’ve done wrong?
Thanks!
WPBeginner Support
Hi Elizabeth,
There is an unexpected asterisk sign in the code on line 9 which is blocking the php script. Edit the file again and copy the code exactly as it is shown above. Make sure that you don’t copy line numbers in the code click on the Copy button at the top right corner of the code snippet box
.
Admin
Steven Denger
I tried naming the new folder as you did in the example but I got an error that said something in the way of you cannot use a name like this. This Instruction may be helpful to some – but it is very difficult and confusing to me and does not help at all. As I said – you need to explain this down to the fine details or otherwise these tutorals will not help. The name of this site is wp BEGINNER – and that is what I am. You project these tutorals to the more experienced.
I guess I will have to start going elswhere to get beginners instructiions because, most of time, wp beginner is not helpful – it is more like a techs only club.
Steven Denger
How do you get to the /wp-content/plugins/yoursitename-plugin/ in wordpress and upload a file there? I am lost on the first line of instruction. You guys always assume that we know these things in your instructions but they are not clear enough.
I went to cpanel and opened up the wpcontent > plugins – and it shows a list of plugins – but I am lost from this point. How do I go about uploading a file in here? I am a beginner – and you guys seem to always explain things like your instructing experienced techs. I am not but I go to WP Beginner to try to learn. It is usually difficult to follow your instructions and I end up having to go somewhere else in google search to find things explained down to a beginners level.
If you want to be more helpful try breaking things down a little more simple.
Manuel
Hey Steven,
I know the feeling! I’m far from a expert with wordpress and I pretty much live on google searches and this site trying to learn. I know a little bit and was able to get this to work. Send me your email and I’ll send you the steps with screenshots. I havent tested putting actual code into the plugin so we’ll see if that works….but I was able to see the newly created plugin on my admin page
Steven Denger
thank you manuel
NiceRazer
Hello, can you please tell me how to do that to? I’ve tried finding posts that would help me with this same prob but still didnt found it.
JoAnn Chateau
Thank you for the great advice and simple how-to instructions. I easily created a Site-Specific WordPress Plugin for my site and enabled shortcodes for widgets. Now I have less worry when changing themes, and I didn’t need to install another plugin. Again, thanks!
george
hi i followed the instruction on how to make a site plugin for my site. ive uploaded it but cant see it in my list of plugins.
any ideas why?
Dawn
I cannot find where the folders live in the plug in directory. I tried searching for: /wp-content/plugins/yoursitename-plugin/ (with my site name).
Kara
Never mind, I figured it out and got it activated. My hosting server was acting up, must have timed out or something…cheers!
Kara
I followed your instructions but i don’t know how to activate it. It doesn’t show in my list of plugind in my wp-admin. Can you help?
Sheyejinkazama
Thank you. Thank you so so much.
Molly
How do you get the plugin to “Network Activate” on a multi-site?