The current version of EE4 is 4.9.26.p [ My Account | EE4 Changelog | Demo EE4 | Download EE4 Decaf ]

How to Create a Site Specific Plugin for your WordPress Site

How to Create a Site Specific Plugin for your WordPress Site

Today we will learn how to create a site specific plugin for our WordPress site. Before we get started on creating the file, lets briefly talk about why these plugins are helpful.

In the past, if you wanted to add a code snippet to your site then you might use your theme’s functions.php file which is usually in this location:

wp-content/themes/yourthemefolder/functions.php

The problem with this approach is that it does not account for theme updates which means there is a risk of losing your customizations if you update your theme. This is especially true if your theme has a convenient one-click update feature from within the WordPress admin. A site specific plugin is a better choice since your customizations will be in organized in one location. Additionally, if you add your code through the WordPress Plugin Editor, then WordPress will check your code to ensure that it won’t cause any fatal errors and take your site offline.

Create your Site Specific Plugin

To get started, you will need to login to your WordPress root with an SFTP or FTP client. Cyberduck and FileZilla are free options that are available on multiple platforms. This will require an SFTP or FTP login which can be provided by your web host.

1) After logging in to your WordPress root, browse to this location:

wp-content/plugins

2) Now create a new folder. In this example, we’ll create one called myexamplesite:

site-specific-create-folder

3) Next, open the new folder that you just created.

4) We now need to create a file. In this example, we will create a file called myexamplesite-customizations.php:

site-specific-create-file

5) Then, copy the sample code below:

<?php
/*
Plugin Name: Site plugin for myexamplesite.com
Description: Site specific code for myexamplesite.com
*/
/* Begin Adding Functions Below This Line; Do not include an opening PHP tag as this sample code already includes one! */

/* Stop Adding Functions */

6) Return to your SFTP or FTP client and paste the sample code above into the file. You can change “myexamplesite.com” to something else such as your own site URL. Be sure to save changes to the file.

6b) You may need to update the file permissions for the file. Check with your web host for the required file permissions.

7) Now login to your WordPress admin and go to Plugins –> Editor. Select your new plugin from the dropdown in the top right corner:

site-specific-select-plugin

You can now add your code snippets to this file and save changes by clicking on Update File.

Remember, by using the WordPress Plugins Editor, WordPress will check your code to ensure that it won’t crash your site and now your customizations will be protected from theme updates.

References:

http://ottopress.com/2011/creating-a-site-specific-snippets-plugin/

http://www.wpbeginner.com/beginners-guide/what-why-and-how-tos-of-creating-a-site-specific-wordpress-plugin/


Need more help?

Do NOT follow this link or you will be banned from the site!
[gravityform id=69 title=false description=false ajax=true]
  • This field is for validation purposes and should be left unchanged.