Do you want to incorporate a site-specific plugin into your WordPress website? A site-specific plugin lets you easily add code snippets to your WordPress website without having to rely on your theme. In this article, we’ll go over how to make a site-specific WordPress plugin and why it’s important.
What is a WordPress Plugin for a Specific Site?
A site-specific WordPress plugin is a stand-alone plugin that allows users to add all customization snippets which are not theme-dependent.
When working on your website, you’ll frequently come across WordPress tutorials that instruct you to add code to your theme’s functions.php file or a site-specific plugin.
WordPress does not include a site-specific plugin. You must first create your own, then install and activate it.
Why Make a WordPress Plugin for a Specific Site?
As stated earlier, you will frequently come across tutorials that demonstrate some code that you can attach 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 a plethora of other website enhancements.
If you add the custom code to your theme’s functions file, it will be removed when you update or switch themes. You can save your code by creating a child theme and using its functions file. However, if you switch themes, your code will be lost.
A site-specific WordPress plugin enables you to easily add custom code snippets to your WordPress website while ensuring that they are theme independent. It is a stand-alone WordPress plugin, so it is not dependent on your theme, and you can update or switch themes at any time.
Having said that, let’s look at how to easily add custom code using a site-specific plugin. We’ll show you two methods, and you can pick the one that works best for you (hint: Method #2 is easier for beginners).
Method 1: Create a Site-Specific WordPress Plugin by Hand
We understand that this may sound a little geeky to newcomers, but we will do our best to make it as simple as possible for you.
To begin, make a new folder on your desktop and name it after your website, such as mywebsite-plugin.
Now, on your computer, launch a plain text editor such as Notepad or TextEdit. Create a new file and save it as mywebsite-plugin.php in your desktop’s plugin folder.
Your plugin file requires a specific header code in order for WordPress to recognize it as a plugin. Insert the following code into your mywebsite-plugin.php file:
- 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 use your own domain name instead of example.com. After that, your site-specific plugin will be ready.
There are two methods for adding a site-specific plugin to your website. You can either use your WordPress admin panel or FTP to upload it.
1. Download and install the Site-Specific Plugin from the WordPress Admin Area.
This method is more convenient and is recommended for all users.
First, make a zip file of your site-specific plugin folder.
Users on Windows can simply right-click on the plugin folder and choose Send to » Compressed (zip) folder.
Mac users must right-click and choose “Compress mywebsite-plugin.”
Once you have the zip file for the plugin, navigate to the Plugins » Add New page in your WordPress admin area and click the ‘Upload Plugin’ button at the top.
Then, click the choose file button to select the zip file you made earlier, and then click the ‘Install Now’ button.
WordPress will now automatically upload and install the plugin. Once uploaded, click the activate button to begin using your site-specific plugin.
2. FTP-Upload Your Site-Specific WordPress Plugin
You do not need to create a zip file for this method. You will be using FTP to upload the plugin.
To begin, use an FTP client to connect to your website.
After connecting, navigate to the /wp-content/plugins/ folder in the remote site column. Then, choose your site-specific plugin folder and upload it to your website.
Your site-specific plugin folder will now be transferred to your WordPress website via your FTP client. The plugin will be installed on your website as a result of this.
However, in order to use the plugin, you must first activate it. You can do so by proceeding to the Plugins page in your WordPress admin area and thereafter clicking on the ‘Activate’ link beneath your site-specific plugin.
That’s all there is to it. Your site-specific plugin is now complete and ready to use.
Adding Site-Specific Plugin Custom Code Snippets
There are two methods for editing your plugin and adding custom code snippets.
The first method is to use the WordPress admin area. You can navigate to the Plugins » Editor page. You will see a warning message and must click the ‘I understand’ button to proceed.
Then, from the drop down menu labeled ‘Select plugin to edit,’ choose your site-specific plugin. The editor will open your plugin file and allow you to add code snippets to it.
When you’re finished, click the ‘Update File’ button to save your changes.
If something is missing from your code or if it has the potential to break your website, the plugin editor will undo your changes.
If the editor fails and you see the white screen of death, you can use FTP to edit your plugin file and reverse the changes.
The second method is to use FTP to directly edit the plugin file. Using your FTP client, navigate to the plugin folder. Select View/Edit file from the context menu when you right-click on the plugin file.
You can also save the plugin file to your computer, modify it, and then re-upload it.
Method 2: Make Use of the Code Snippets Plugin
This method is much easier to use and provides a better way to manage your individual code snippets in WordPress.
The first step is to install and activate the Code Snippets plugin on your website. See our step-by-step guide on how to install a WordPress plugin for more information.
When you activate the plugin, it will add a new menu item to your WordPress admin menu called “Snippets.” This is where you will keep track of all your custom codes.
To add a custom code, navigate to Snippets » All Snippets and click the ‘Add New’ button at the top of the page.
This will take you to the page titled ‘Add New Snippet.’
First, give your custom code snippet a title. This could be anything that aids in the identification of the code.
After that, simply copy and paste your code snippet into the code box.
In the field below the code box, you can also add a description of the code. Use this section to describe what this code does, where you found it, and why you’re including it on your website. This will assist the “future you” in remembering why the “past you” included this code.
You can also assign tags to your code snippets, which can help organize them by topic and functionality.
Finally, press the ‘Save Changes and Activate’ button. If you only want to save the code snippet without activating it, you can do so by clicking the save changes button.
The plugin also allows you to specify where the code snippet should be executed. You have the option of selecting the admin area, front-end, or everywhere.
If you’re not sure, leave the default ‘everywhere’ option selected.
When you save and activate a code snippet, it becomes active on your website.
We hope this article has helped you understand why and how to create a WordPress plugin for your website.
If you liked this post, please find and follow us on Instagram, Twitter and Facebook.