8

I have taken it upon myself to adhere to WordPress conventions so I can have a clean, sexy child theme. However, I am unsure how to proceed on a certain issue.

I would like to override the CSS for some plugins in my WordPress website, and this wonderful post was a great step in the right direction. My only concern is that I would like to do everything I can to avoid overriding the header.php file in my parent theme in order the do this.

Is there another wonderful way to do this? Thanks for your help!

Update:

As was pointed out by another user's comment, this is in fact dependent on how the plugin implements its styles. This aside, assume that the plugins do provide a way for styles to be implemented in the style.css sheet of the child theme, or, in my case, a separate styles folder linked to that style.css sheet.

I also know I can use !important all over the place, but this is generally frowned upon.

5
  • it depends entirely on how the plugins in question are adding their styles.
    – Milo
    Commented May 28, 2013 at 17:19
  • I updated my post to accomodate your comment. Thanks! Commented May 28, 2013 at 17:27
  • Close-voted as not constructive. Please edit your question to refer to specific Plugins, and include the specific CSS implementation code for those Plugins. Commented May 28, 2013 at 20:00
  • I would love to, but unfortunately this is a pretty general question. My goal is to encapsulate all stylesheets that add custom edits to any plugin's styling in a single folder in my child theme. This keeps some really clean code, and is very efficient. I will add specific, code, though! Commented May 29, 2013 at 16:58
  • I just found this Simple Custom CSS plugin It handles everything discussed for enqueuing dependent CSS. Simple to install and use.
    – user41251
    Commented Sep 14, 2014 at 19:25

1 Answer 1

17

If the plugins are correctly adding their styles via wp_enqueue_style, you simply need to dequeue them:

function wpa_dequeue_style() {
    wp_dequeue_style( 'plugin-style-handle' );
}
add_action( 'wp_enqueue_scripts', 'wpa_dequeue_style', 100 );

Whether or not this works depends on how and where the plugins are adding their styles, so there's no absolute answer without knowing specific methods the plugins in question use.

EDIT- another option that doesn't involve removing the styles entirely is to enqueue your own styles with the plugin styles as a dependency:

wp_enqueue_style(
    'my-styles',
    get_template_directory_uri() . '/mystyles.css',
    array('plugin-style-handle')
);
5
  • This is certainly a step in the right direction. However, my overrides are edits, so the trade-off of copy-pasting the entire stylesheet and editing it is a bit counter-productive. Like you said, it's also entirely dependent on how the css is added. Commented May 28, 2013 at 17:39
  • 3
    see edit above.
    – Milo
    Commented May 28, 2013 at 17:44
  • I'll give that edit a shot. That looks like a great idea! Commented May 29, 2013 at 16:58
  • 1
    Wow, I can't upvote enough. It worked! Commented May 29, 2013 at 19:20
  • It's an old answer but helped me in 2020. Thanks!
    – Kinburn101
    Commented Jan 10, 2020 at 4:46

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.