Skip to main content
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

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 answerthis answer or this answerthis 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?

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?

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?

Source Link
Lea Cohen
  • 1.6k
  • 3
  • 22
  • 45

Let user override plugin CSS

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?