0

So this is not a transferrable question to other sites out there, but I am creating a Wordpress multisite for internal use at our office and instead of duplicating the theme CSS, JS, and other assets I created it all into one MU-Plugin.

I know this is not standard practice, but I am the only one managing the sites, and it is more a set up and forget.

At the moment I am currently calling on a base.css that has some normalisation and then any unique css is being called from:

$themeName = wp_get_theme()->get('TextDomain');
$themeName = get_template();
wp_enqueue_style( 'solo_css',       network_home_url( $themeName . '.css'), array( 'main_css' ),    globalVersion );

However, because I am manually doing al this, and hoping to expand the multisite soon to other ventures internally I don't want to create a solo_css file for each of the new sites.

Is there a way to create the file in the plugin folder on theme activation? Again, I know it's not recommended practices or transferable, but something make the repetitive nature easier.

2 Answers 2

1

Take a look at after_switch_theme link

But I would use hooks to insert the css for example in wp_head

This link helps you get the directory of the theme, so you can create the css afterwards.

0

@Кристиян Кацаров is correct in the handling of when to do the function, but I ended up writing something that doesn't use any WP inbuilt functions (which I was hoping there was).

function default_css_dir() { 
    $themeName  = wp_get_theme()->get('TextDomain');
    $themeName  = get_template();
    $cssPathway = ( ABSPATH . 'wp-content/plugins/pluginname/' . $ThemeName . '.css' );

    if( !file_exists($cssPathway) ) {
        $fileCSS = fopen( $cssPathway, 'wb' );
        fwrite( $fileCSS, '' );
        fclose( $fileCSS );
    }
}

Again, won't work unless you're 100% sure it won't ever be altered, and the plugin will be active. But internally works wonders.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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