I have a wordpress setup that I use for clients with around 30 or so child themes that they can choose from. Each child theme has it’s own functions.php file currently. Is it possible to setup just one child functions.php and call it from all the separate child themes? My reason for wanting this functionality is I find myself continually making changes to the functions.php and I have to do it to all 30+ themes every time.
4 comments
Comments are closed.
Well, I’d say that you need a custom plugin. All the rationale is in this Q&A:
Where to put my code: plugin or functions.php?
Also related:
And answering to the Question, create the following file
/wp-content/themes/common-functions.php
, and paste what you need in it. And inside the child themefunctions.php
use:or
Use a plugin for that. Hook into
after_setup_theme
and check if the current theme is the correct child theme:wp_get_theme()
returns aWP_Theme
instance, andparent()
either the parent theme name orFALSE
.I do not recommend a mu-plugin. Real plugins can be deactivated, and you can enable or disable them for each site separately. Adjust the capabilities for the clients instead; this is a much cleaner approach.
I’d use a must use plugin. The code will apply across the network while your clients won’t have access to it so they won’t be able to disable or modify it.
To proceed you just have to put your code in one single file and put it in /wp-content/mu-plugins/
Hope this will help 🙂
You can
include
just about any file you want from any of the child themes, but there is little known feature to WordPress called Must Use plugins. I think I would lean towards that.wp-content
Unlike ordinary plugins, must-use plugins do not show up in the plugin list and cannot be deactivated, other than deleting the mu-plugin file, so they can serve as a kind-of global
functions.php
.