Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

4 Answers 4

up vote 6 down vote accepted

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 theme functions.php use:

require_once ( TEMPLATEPATH . '/../common-functions.php' ); 

or

require_once ( WP_CONTENT_DIR . '/themes/common-functions.php' ); 
share|improve this answer
1  
I was going to say put it above the web root, but you this works too. –  Andrew Bartel May 1 '13 at 20:13
add comment

Use a plugin for that. Hook into after_setup_theme and check if the current theme is the correct child theme:

add_action( 'after_setup_theme', 'common_child_theme_functions' );

function common_child_theme_functions()
{
    if ( 'Twenty Twelve' !== wp_get_theme()->parent() )
        return;

    // do your work
}

wp_get_theme() returns a WP_Theme instance, and parent() either the parent theme name or FALSE.

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.

share|improve this answer
add comment

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 :)

share|improve this answer
1  
Sorry I was writing this and s_ha_dum post the same answer before. –  JMau May 1 '13 at 20:23
    
There's something that needs to be taken into account: running the mu-plugin only in specific sites, otherwise it runs in all of them. & welcome to WPSE :) –  brasofilo May 1 '13 at 20:57
    
Thanks brasofilo. You're right but Tory wanted it for all. Maybe if for some reasons one or more sites need to be excluded it is easy to put this in a if statement like : global $blog_id; if($blog_id !== ...etc) –  JMau May 1 '13 at 21:04
add comment

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.

  • Create a directory called mu-plugins in wp-content
  • Create a file in that directory and add your functions to it.

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.