Generally bloggers tend to write custom php functions in the theme function.php file. I was also no exception and used to practicing it until I lost my custom functions (which had been saved in the theme function file) on account of forgetting to copy all functions before updating my blog theme. However, I recovered overwritten function.php file from the most recent backup copy of my blog. (I always take the automatic backup of my blog files and database on a daily basis – read more). But the whole rigmarole took a lot of time which otherwise could have been put to more productive use. Similarly, if I had not had a backup, It would have definitely been a harrowing experience to recover several custom functions in theme function.php file.
After that I decided to keep my custom WordPress PHP Code at a place which was safe and updating WordPress core, themes or plugins couldn’t affect the code. I had two choices;
Either keep all functions in database via a plugin
or Save them in a plain plugin file that could be created easily
My Custom Functions by Arthur Gareginyan
It is an amazing simple plugin that lets you add all your custom functions in the database. This plugin has its own interface to add custom functions. You can add unlimited custom functions with the help of this plugin. You might think what would happen if you happened to add a wrong php array that might return a syntax error? We all know that we can’t access WordPress admin panel in most of php parse syntax error. If a plugin saves php code in the database, it is pretty annoying to figure out that code in the database using phpmyadmin. But that is not the case with this plugin. This plugin does not allow you to submit a php code until it is valid. If you add a code piece that may trigger a syntax error, it will simply refuse to submit the code and tells you the reason of refusal.
Apart from that, you can enable or disable custom functions any time with the help of an ON/OFF switch. This plugin uses php editor powered by CodeMirror that highlights syntax and also gives number to lines.
Features of My Custom Functions plugin at a glance
- Syntax error protection
- saves PHP functions in database
- uses PHP editor and syntax highlighter by CodeMirror
Download link is locked
[sociallocker id=”5255″]
[/sociallocker]
Create a plugin
You can create a simple plugin to save all your custom php code. It is very easy to this. Simple open your pc notepad and put the following code in it;
Plugin code /Download link is locked
[sociallocker id=”5255″]
<?php
/**
* Plugin Name: Custom Functions
* Plugin URI: http://example.com
* Description: This is an awesome custom plugin with functionality that I’d like to keep when switching things.
* Author: Your Name
* Author URI: http://yoursite.com
* Version: 8.0
*/
/* Add custom code below */
/* Add custom code above */
?>
Alternatively you can download the plugin file here
[/sociallocker]
Save this file with the name and extension like this;
mycustomcode.php
Upload this file to your plugin directory
You can add your custom php functions between comment lines. You will have full control on this php file. All you need to do is activating this plugin. You can add custom code to this plugin using WordPress plugin editor, via FTP or hosting file manager.
You are free to change plugin name, URL, Description, Author, Author URL and version.