Normally in a plugin I would add styles using wp_enqueue_style. However, I am currently creating a plugin that only needs a few lines of CSS and I am wondering if it might be better to serve the styles inline to save a request. Obviously there are many advantages to using wp_enqueue_style, but are they worth the extra request for such a small piece of CSS? Is there any accepted 'best practice' in this area?
|
TL;DR; Using external stylesheet
Using inline styles
Normally I would say: Sure, if you are the only one using it, go ahead and do it inline. But you are talking about a plugin which means the code will be public so aim for extendibility. Right now you only have a few lines of styling:
Therefore, enqueue. (Preferably Conditionally only if the plugin needs it.) The same applies to JavaScript. (But that should be included in the footer if possible.) |
|||||||||||||||||
|
|
This is hard to answer and I am really not sure if there is an official answer. I understand the sentiment about saving a request but inline style pretty much always wins. A theme or end user will have a hard time altering your CSS. With that in mind, I think I'd do this in a publicly released plugin...
|
|||
|
|