0

I'm searching for the "right way" to add a custom.css file after the 3rd party plugin has loaded theirs. I know how to register and enqueue my css files in functions.php. Can I somehow add a dependency for the 3rd party plugin stylesheets? For example I want to load a custom.css file afer the plugin woocomerce has loaded. I want this without editing the plugin. Can this be done in functions.php?

1
  • You can dequeue and enqueue the woocommerce stylesheets in your functions.php file and/or set a higher priority to your custom styles when enqueueing. Commented Jan 15, 2019 at 20:21

1 Answer 1

2

The most correct way to do this would be to just utilize woocommerce's general stylesheet as a dependency using wp_enqueue_style().

add_action( 'wp_enqueue_scripts', 'my_woocommerce_styles' );
function my_woocommerce_styles(){
    wp_enqueue_style( 'my-wc-style', 'path/to/my-styles.css', array( 'woocommerce-general' ), '1.0' );
}

Woocommerce has multiple stylesheets registered under different handles - but you're most likely looking for woocommerce-general.

Using it as a dependency like that will only load it if woocommerce-general has been loaded for that particular request, and it will load it afterwards. You may need to adjust the priority of the add_action depending on exactly how/where you're doing this. You mentioned functions.php so it shouldn't be necessary, but you if you need to, just pass another priority to it, for example:

add_action( 'wp_enqueue_scripts', 'my_woocommerce_styles', 15 );
Sign up to request clarification or add additional context in comments.

1 Comment

@ShawnHayes - you're absolutely correct! I've updated the snippet. Thanks for pointing that out

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.