0

I'm writing a plugin, which has a certain style. However, that style won't suit every site. therefore, I would like to let the site admin override the plugin CSS if they want. How would I go about doing that?

I'm also trying to think of a way to let a theme override the plugin CSS.
I could go the way this answer or this answer suggest:

  • Provide a way to disable the plugin CSS;
  • Enqueue the plugin CSS using a hook, by which letting the theme unhook it;
  • Trust the theme devloper to know they can enqueue the theme's own styles with the plugin styles as a dependency.

But I'm not sure if the ways suggested are just ways to solve the problem after the plugin is already written, or are best practice.
On the other hand, I was thinking maybe in my plugin I could check for a specific CSS file in the theme, and - if it exists - enqueue it after the plugin CSS. Does that make sense?

1 Answer 1

0

How about having the location of the CSS file set as an option for the plugin in the admin area?

The default setting would be your default stylesheet. The option would allow this to be changed to another specific stylesheet by the user, or removed entirely.

If this option exists, your plugin enqueues the stylesheet.

This allows the user to:

  1. replace default stylesheet with their own, in any location
  2. not use stylesheets in the plugin at all and apply them from a stylesheet elsewhere
  3. change stylesheets by de-queueing the plugin's and queuing their own

I think I've seen this in a plugin but I can't remember which!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.