1
votes

I am running a wordpress multisite server with more than 15 domains.

What I would like to do is manage the style.css and functions.php for all for all of the domains from one file for all domains (1 style.css 1 functions.php) because a majority of the styles and functions are the same across all of my domains, however I would like the option to add domain specific options in each child theme.

Can this be done or would it be a bad idea?

1

1 Answers

1
votes

We actually do something similar. What I've done is created a PHP file in the /mu-plugins/ directory. PHP files in there will load regardless of active theme or plugins.

You can read up on Must Use Plugins in the Codex. They work just like a plugin but are always loaded and can't be activated/deactivated.

So if you create /wp-content/mu-plugins/lahree.php and /wp-content/mu-plugins/lahree.css, you'll be able to treat the .php file like a global functions.php of sorts (since it's always loaded). From there you can enqueue the .css file to effectively use it as a network-wide/global style.css file.

Inside the functions in the lahree.php file you can compare the current blog name, site url, or even active theme to load specific stylesheets or run certain functions just on those specific sites.

You can see in the Action Reference that the mu-plugins files are loaded incredibly early, so you may need to adjust the priority of add_action hooks if you're planning on overwriting styles loaded in the theme.

lahree.php would look something like this:

<?php
    add_action( 'wp_enqueue_scripts', 'wlnb_wp_enqueue_scripts' );
    function wlnb_wp_enqueue_scripts(){
        wp_enqueue_style( 'lahree-global', WPMU_PLUGIN_DIR. '/lahree.css' );

        if( site_url() == 'SPECIFIC_SITE_URL_1' )
            wp_enqueue_style( 'lahree-site-1', WPMU_PLUGIN_DIR. '/lahree-1.css' );

        if( site_url() == 'SPECIFIC_SITE_URL_2' )
            wp_enqueue_style( 'lahree-site-2', WPMU_PLUGIN_DIR. '/lahree-2.css' );      
    }

    add_action( 'wp_head', 'do_something' );
    function do_something(){
        if( site_url() == 'SPECIFIC_SITE_URL_3')
            echo 'This is the Third Site';

        if( site_url() == 'SPECIFIC_SITE_URL_4')
            echo 'This is the Fourth Site';
    }