How to Create a Custom Functions Plugin

There will come a time when you need some new and shiny feature added to your blog, but there isn’t a plugin for it. In fact all you have managed to find on the internet is a small function that will do the job nicely.

The problem is, is that you add it to your themes functions.php and the next day (week, month) the theme gets a new version, and you update without thinking about the function and bam! it’s gone.

This is because when a theme or plugin is updated, the old version is actually deleted first and the new version installed in its stead.

You could of course create a Child Theme and use the functions.php there, but sometimes a Child Theme is overkill, when you just need to add a function or two. That’s where a Custom Functions Plugin comes in.

All it is is an empty plugin that you can add functions to via the Plugins > Editor screen or via FTP/cPanel if you prefer.

Because it’s a plugin, the theme updates have no effect on it whatsoever, so you can happily forget you added that amazing function without worry when update time is here.

What you need

In order to create a custom function you will need access to a text editor (Notepad is fine, just don’t use Word or any word processor) and either an FTP client such as FIlezilla or the ability to zip a file (the latest Windows can do this by right clicking and then Send To and then Compressed (Zipped) folder).

Getting started

Open Notepad and straight away click File > Save As. When the save pop up comes up, change the Save as type option at the bottom to All Files and change the file name to something.php (the something can be anything you want but just don’t forget the .php!).

This will create a blank PHP file to work with.

Once the file is created add the following code to it.

All this code does is tell WordPress that this file is a plugin. You can change the information in the above code should you wish, but you need to keep the structure the same.

Uploading the plugin

If you just have the single file as is, you can use your FTP client to upload the file directly into wp-content/plugins/. You don’t need to worry about giving it it’s own directory though you can if you wish or if you plan to add more files to the plugin in the future.

If you can zip the file, you don’t even need to use FTP, just go to the Plugins > Add New menu in your site and click the Upload link and upload the file from there. Again, you can insert the file into a folder first and zip that or just zip the file itself.

Using the Custom Functions plugin

After activating the plugin, absolutely nothing should happen. That’s because it’s empty! In order to use it you need to add some functions to it.

You can add them in several ways:

The plugin editor page

This is perhaps the easiest way. If you go to Plugins > Editor and then select the plugin from the drop down, the file will be shown and you can edit it from there.

Create a Custom Functions Plugin - Plugin Editor Screen

Direct via cPanel

Most hosts offer some sort of control panel and in turn they have file managers. From those it is possible to edit the files content.

On your computer

Editing the file directly on your computer and then uploading via FTP or the WordPress plugin screen is pretty easy to do. With FTP you will need to over write the existing file. With the WordPress method, you will need to delete the existing plugin and then install the new version, otherwise the install will fail.

Whichever way you do it, I still recommend testing the functions out on a development first to make sure that everything is in order. If not, at least have FTP access handy so that you can rename the plugin folder should something go wrong (this will deactivate the plugin). 

A word about functions

Some functions you find on the internet will come with an opening <?php tag at the start. You need to remove that from the code as your plugin already has a tag at the top. There are times when you need this tag but with pre-made code snippets it isn’t often. The same goes for the closing ?> tag too.

Create a Custom Functions Plugin - PHP Tags


Now that you can add a simple custom functions plugin, there is nothing to stop you from adding some fancy functions to spruce up your website and improve your visitors experience, all without having to worry that updates will delete your hard work!