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 badges2 Answers
Reset to default 1Take 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
版权声明:本文标题:multisite - Create a CSS file in plugin folder when theme is activated 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745290501a2651764.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论