How to Create a Site Specific Plugin

A common question I get when supporting WordPress users is “where to I put this custom code snippet.”

A frequent and simple answer to that question is, “In your theme’s functions.php file.”

While that’s not necessarily a wrong answer, it’s not the best answer. Putting custom code snippets in your theme’s functions.php means that if you change themes, you have to migrate all that code.

A much simpler solution is to create a site specific plugin to store your custom code. That way, all of your customizations stay with you.

But how do you do that?

I have a simple site specific plugin framework available on github that you can use for any and all of your custom code snippets. You can use it as-is, or you can add additional files if you want to separate custom code by different groupings (such as customizations for multiple plugins). You could also copy and rename the plugin to create separate plugins within a single site.

How to get started

To get started, copy the entire package from github. Rename files as needed.

The core file structure consists of the following:

|– site-specific-plugin.php – The plugin initialization file.
|– readme.txt – A standard WP plugin readme file.
|– license – The GPL license.
|– custom/
|– functions.php – A file to contain your custom PHP functions.
|– custom.js – A file to contain your custom JS.
|– style.css – A file to contain your custom CSS.

Install the folder as you would a regular plugin. Once activated, you can edit locally and upload changes via FTP or you can edit using the WordPress plugin editor. Use caution if editing live on the site – if you make a code error, this could crash your site.

Leave a comment

Your email address will not be published. Required fields are marked *