admin管理员组文章数量:1334887
When we create Wordpress sites for clients I like to use mu-plugins to add custom stuff to make my job easier. The main thing I like about mu-plugins is that the client can't shut them off and they're update proof. That being said. Can I add simple css to an mu-plugin?
When we create Wordpress sites for clients I like to use mu-plugins to add custom stuff to make my job easier. The main thing I like about mu-plugins is that the client can't shut them off and they're update proof. That being said. Can I add simple css to an mu-plugin?
Share Improve this question edited Sep 17, 2019 at 21:40 Howdy_McGee♦ 20.9k24 gold badges91 silver badges177 bronze badges asked Sep 17, 2019 at 21:36 Eric KowalewskiEric Kowalewski 91 bronze badge 5- I'm not sure if I understand. What kind of CSS? Where should that code be outputted? – Johansson Commented Sep 17, 2019 at 21:49
- Say I wanted to target the adminbar in the backend and change the color. – Eric Kowalewski Commented Sep 18, 2019 at 1:34
- Yes, you can. Are you actually asking how to do it? It wouldn't be any different to a regular plugin, except that MU plugins are a single PHP file only, so you'd need to write the CSS in a PHP function, or store the CSS file somewhere else. – Jacob Peattie Commented Sep 18, 2019 at 8:58
- Ok. Could you give me a simple example? I just can't get it to work. I tried this nice lady's blog, but it didn't work: nastia.rocks/how-to-add-css-code-in-mu-plugin – Eric Kowalewski Commented Sep 18, 2019 at 13:30
- Anyone? I can’t be the only one. I’m not really that revolutionary? Lol – Eric Kowalewski Commented Sep 20, 2019 at 20:20
1 Answer
Reset to default 4You can actually put a directory for your style sheet right in the mu-plugins directory. I called mine "my-companies-assets". The tricky part is calling your styles into your mu-plugin. In your main MU plugin file...
// Setup MY AWESOME MU plugin url
// This will help if you switch to multisite some day
if (is_multisite()) {
define('MY_AWESOME_MU_PLUGIN_URL', network_site_url('/wp-content/mu-plugins', 'relative'));
} else {
define('MY_AWESOME_MU_PLUGIN_URL', content_url('/mu-plugins'));
}
// Then you can just use wp-enqueue_style like normal
wp_enqueue_style( 'my-mu-styles', MY_AWESOME_MU_PLUGIN_URL.'/my-companies-assets/styles.css', array(), 1 );
/**
* The rest of your plugin code
* goes here
*/
本文标签: Can I add custom css to an muplugin
版权声明:本文标题:Can I add custom css to an mu-plugin? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742371403a2462308.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论