Almost every WordPress user out there will face a situation where they should add a chunk of code into the functional files to add, increase or modify certain features of their WordPres site. The general approach to this is to place the block of code directly into the theme’s
While there is nothing wrong with this approach, it doesn’t make any sense to add all that functionality into a theme file while it is not related to your theme in the first place.
Moreover, adding all the code snippets in your theme’s
functions.php file makes it hard to manage and a single mistake may break your site. But with a site specific plugin, you can avoid all that hassle. So in this quick tip, let us see how to create the site-specific plugin so that you can add all the code found on the web that is not related to your theme into that plugin.
Benefits of Site-Specific Plugin
- The code that you add via site-specific plugin works even if you change your theme in future.
- Even if there is some error in the code, your site doesn’t break (most of the time). Moreover, you can simply disable the plugin if needed.
- The code added to the site-specific plugin is easier to maintain.
What Kind of Code Should I Add to Site Specific Plugin?
When I say code snippets that are not related to your theme, I am taking about the functionalities you add that doesn’t depend on your theme. Some examples would be.
- Adding a code snippet to redirect users.
- Adding confirmation boxes.
- Custom post types.
- To insert ads between posts.
- Code that customizes specific parts of your WordPress site regardless of the theme you are using (like the comments section).
- Anything that is not related to your theme.
Create Site-Specific Plugin
Creating a site specific plugin is a lot easier than you think.
1. First off, just create a new text file and name it
2. Now, open the text file using your favorite text editor and add the below code. Also, don’t forget to change the example.com text.
<?php /* Plugin Name: Site Specific Plugin for example.com Description: Add Site Specific Code Snippets to example.com Author: <a href="https://www.bloggersignal.com">Bloggersignal</a> */ /* Add code snippets below this line */ /* End adding code snippets */ ?>
3. Once you have done that, simply save it and close the file. If you have problems creating the file, download the sample site specific plugin by Bloggersignal.
4. Now fire up your favorite FTP client and navigate to
/wp-content/plugins/ directory. Here create a new folder named “YourDomainName-plugin.”
5. After creating the folder, navigate to it and upload the file
yourdomainname-plugin.php into it.
6. Once you have uploaded the file, open up your WordPress admin panel and activate the plugin.
That’s all there is to do. From this point forward, you can add any code snippets you found on the web directly to the site-specific plugin rather than the theme functions.php file.
Hopefully that helps and do comment below if you face any problems or to share your thoughts and experiences about using the site-specific plugin.