WP SITES

3086 Coded Tutorials & 289 Plugins

How To Deregister & Dequeue Style Sheets

WordPress includes 2 functions which you can use in your child themes functions.php file to deregister and dequeue style sheets for themes and plugins.

Deregister a CSS file that was registered with wp_register_style().

wp_deregister_style()

Dequeue a CSS file that was enqueued with wp_enqueue_style().

wp_dequeue_style()

Using the same function, you can correctly enqueue your own style sheets.

add_action( 'wp_enqueue_scripts', 'remove_default_stylesheet', 20 );
function remove_default_stylesheet() {

wp_dequeue_style( 'original-enqueue-stylesheet-handle' );
wp_deregister_style( 'original-register-stylesheet-handle' );

wp_register_style( 'new-style', get_stylesheet_directory_uri() . '/new.css', false, '1.0.0' ); 
wp_enqueue_style( 'new-style' );

}

Simply replace original-enqueue-stylesheet-handle with the name of the handle that was used to enqueue and/or register the default style sheet for any plugin or parent theme.

This code enables you to move a plugins stylesheet to your child theme and style it there so any plugin updates don’t override your custom styling for the plugin.

You could also use this code to remove the styles from a parent theme and add your own in your child theme.

If you don’t want to enqueue a new style sheet for a plugin or theme, you can simply add the CSS code at the end of your child themes style.css file.

Related Solutions

11 responses to “How To Deregister & Dequeue Style Sheets”

  1. Hello,
    Let me ask something: if I want to use 2 different css styles on my WordPress website, should I deque first the old css style for the page where I want to apply the new css style?
    Thank you!

    1. Brad Dalton Avatar
      Brad Dalton

      Happy to help however please provide your membership username.

  2. Customizing default Mediaelement player – Internet and Tecnnology Answers for Geeks

    […] Looking for an alternate way to do this i found: https://wpsites.net/web-design/how-to-deregister-dequeue-style-sheets/ […]

  3. [ASK] wordpress – Customizing default Mediaelement player | Some Piece of Information

    […] Looking for an alternate way to do this i found: https://wpsites.net/web-design/how-to-deregister-dequeue-style-sheets/ […]

  4. Customizing default Mediaelement player | TRIFORCE STUDIO

    […] Looking for an alternate way to do this i found: https://wpsites.net/web-design/how-to-deregister-dequeue-style-sheets/ […]

  5. Customizing default Mediaelement player | Asking

    […] Looking for an alternate way to do this i found: https://wpsites.net/web-design/how-to-deregister-dequeue-style-sheets/ […]

  6. Remove and Replace Child Themes Style Sheet Conditionally

    […] How To Deregister & Dequeue Style Sheets […]

  7. Style Your Plugin Via Your Theme

    […] How To Deregister & Dequeue Style Sheets […]

  8. How to Deregister, Unqueue and Unhook a Parent Theme CSS Stylesheet – WP Zac

    […] Shout out to Brad Dalton over at WP Sites for the original code snippet on How To Deregister & Dequeue Style Sheets! […]

  9. Customizing default Mediaelement player – Wordpress Helpdesk

    […] Looking for an alternate way to do this i found: https://wpsites.net/web-design/how-to-deregister-dequeue-style-sheets/ […]

  10. Tweet Parade (no.05 Jan/Feb 2014) – Best Articles of Last Week | gonzoblog

    […] How To Deregister & Dequeue Style Sheets – WordPress includes 2 functions which you can use in your child themes functions.php file to deregister and dequeue style sheets for themes and plugins. […]

Leave a Reply

New Plugins