How to add code to functions.php in wordpress via a plugin

By | November 27, 2015

Custom code without hacking functions.php

So you wan’t to hack into the code of your wordpress theme to make things more like you want. But for this you need to add some code in the form of a function to the “functions.php” file of your active theme.

This is how its mostly done, but has a little drawback. When you change your theme that piece of code is no longer in effect and you need to code it again in the new theme.

So if you wish to have portability, then it should be done via some kind of a plugin. So that the effect is persistent across themes. And the good news is, that there indeed are few plugins for the task.

1. Functionality Plugin

The Functionality Plugin is a sneaky little plugin that installs itself, and creates a “blank plugin” bearing the name of the site. It creates an option “Plugins > Edit functions” which takes the user to the editor page for the new blank plugin.

The user can add all custom functions inside this new blank plugin and it would run alongside the theme functions and other plugins. Simple and effective.

2. Pluginception

Pluginception is another simple plugin that is similar to the Functionality plugin but with some differences. It adds an option “Plugins > Create a New Plugin” where the user can create multiple new blank plugins and put code inside each of them.

The plugin can then be managed from the Plugins list and code inside these new plugins would work just like other plugins or functions inside functions.php

3. My Custom Functions

My Custom Functions creates a simple option “Appearance > Custom Functions” in the admin panel where you can type in any of your own php code/functions and it would take effect.

The plugin also ensures that the code is error free before applying it. So even if you code contains any syntax errors, you can fix it without having to get inside the file manager.

4. Code Snippets

The Code Snippets is a much more elaborate plugin that has provides the user with a user interface to create and manage multiple snippets each with a name and descriptions. The snippets can be deactivated when not needed.

Leave a Reply

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