admin管理员组

文章数量:1418636

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.

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.

Share Improve this question asked Jul 27, 2019 at 0:59 markbmarkb 2996 silver badges18 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 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.

@Кристиян Кацаров 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.

本文标签: multisiteCreate a CSS file in plugin folder when theme is activated