How do I dequeue a CSS Stylesheet located in wp-content > themes > theme-name > assets > css > theme-skin > color.css?

The outputted code, within the Source Code, is:

<link rel='stylesheet' id='theme-skin-color-css' href='https://www.example.com/wp-content/themes/theme-name/assets/css/theme-skin/color.css?ver=4.9.4' type='text/css' media='all' />

I tried entering the following code, into the functions.php file:

function remove_parent_styles(){
    wp_enqueue_style( 'theme-skin-color-css', get_template_directory_uri() . '/assets/css/theme-skin/color.css' );
remove_action( 'wp_enqueue_scripts', 'remove_parent_styles', 1 );

Unfortunately, this has not worked. It may be worth noting that I am working with a Parent WordPress Theme, where the functions.php file is within the Child Theme.

Is anyone able to see where I may have gone wrong or whether it could be that files in the Parent's 'assets' folder cannot be overridden, so to speak, within the Child Theme etc.


Two things you need to:

  1. Hook into wp_enqueue_scripts with a priority later than the parent theme's. The default is 10 so that's a good assumption. If 11 doesn't work, check the parent theme's source to see which priority it's hooked at.
  2. Use wp_dequeue_style() to do the dequeueing.

That will look like:

function wpse_293836_dequeue_parent_styles(){
    wp_dequeue_style( 'theme-skin-color' );
add_action( 'wp_enqueue_scripts', 'wpse_293836_dequeue_parent_styles', 11 );

Note that you only need the handle of the script/style you want to dequeue. The path doesn't matter. The handle should just be theme-skin-color as WordPress adds -css to the ID.

  • Turns out that all I needed to do was ammend wp_enqueue_style to wp_dequeue_style. With said changes being made, both my orginal and your suggestion works. Thanks for pointing this out. :-) – Craig Feb 12 '18 at 18:34
  • Your code wouldn't have worked with remove_action. It needs to be add_action, and you don't need to pass the path to wp_dequeue_style(). – Jacob Peattie Feb 12 '18 at 21:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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