Can I add custom 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

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
Add a comment  | 

1 Answer 1

Reset to default 4

You 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
*/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742371404a4431336.html

相关推荐

  • Can I add custom 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

    11小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信