I find myself using many of the same snippets of code for my functions.php
file in new websites.
Is there a method I can use to create a few different shared functions.php
files to use across my websites? I am not referring to a WPMU installation, but completely separate installations of WordPress with separate databases, possibly on different hosts.
For example, if there are functions I want to add to a specific site, I would just add them to the site’s own functions.php
, but also have a shared functions.php
file for all my multi-author sites and one for all my single author sites. Another situation would be to group together all similar functions into separate functions.php
files.
UPDATE
Here is an update with an example I found in a premium theme’s functions.php
. This is the only code in the functions.php
, so I assume all the functions are pulled from other files.
$themename = 'CoolTheme';
$shortname = 'cooltheme';
include_once TEMPLATEPATH.'/cool_framework/plugins/pagination.php';
include_once TEMPLATEPATH.'/cool_framework/plugins/cool_widgets.php';
include_once TEMPLATEPATH.'/cool_framework/plugins/sidebar_generator.php';
include_once TEMPLATEPATH.'/cool_framework/cool_comments.php';
include_once TEMPLATEPATH.'/cool_framework/cool_functions.php';
include_once TEMPLATEPATH.'/cool_framework/cool_navigation.php';
include_once TEMPLATEPATH.'/cool_framework/cool_panel/cool_panel.php';
include_once TEMPLATEPATH.'/cool_framework/cool_shortcodes/cool_shortcodes.php';
Is something like this possible, except calling the functions from a completely separate domain or cloud storage? If so, what are the issues, if any, I can expect?
If your functions can go in a single file (no images, or linked js/css files), you could add them to mu-plugin file. See the Must Use Plugins page on Codex for more information.
EXAMPLE:
You would then just save it as
commonfunctions.php
or whatever. Create a folder in thewp-content
directory calledmu-plugins
and place the single PHP file in that folder. It will auto-activate, and can’t be removed from the WP-Admin area.Any issues you might face would depend on the plug-ins or themes that could possibly re-use the same functions causing a conflict.
I would take a look at this article about how to update a self-hosted plugin. This would allow you to setup your functions.php as a functionality plugin and then host it in one place and push updates to all sites. You’d still have to go to each site and update it, but I imagine this would still be an improvement over your current setup.
You also might consider creating a set of options for the plugin that turns on and off sets of functions. Then you could just have a single plugin with all your functions that you then turn on and off per-site.
=====
EDIT: It turns out that there’s even a plugin to help deal with self-hosting plugins. It’s called…wait for it… Self Hosted Plugins. I haven’t used it, so I can’t vouch for it, but it could be worth checking out if the above tutorial doesn’t pan out.