wp_dequeue_style( string $handle )

Remove a previously enqueued CSS stylesheet.


Description Description

See also See also


Top ↑

Parameters Parameters

$handle

(string) (Required) Name of the stylesheet to be removed.


Top ↑

Source Source

File: wp-includes/functions.wp-styles.php

function wp_dequeue_style( $handle ) {
	_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );

	wp_styles()->dequeue( $handle );
}


Top ↑

Changelog Changelog

Changelog
Version Description
3.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Marius L. J.

    To dequeue a style, it has to have been registered before you try to remove it. The best way to achieve this is to set a higher priority for your event and then run it.

    Presume that a theme has the following code:

    add_action( 'wp_enqueue_scripts', 'mywptheme_register_styles' );
    function mywptheme_register_styles() {
    	wp_enqueue_style( 'mywptheme', get_stylesheet_uri() );
    
    }
    

    The above registers a style with the handle `mywptheme` (See the documentation for wp_enqueue_style for more details on how to use it).

    Now in our plugin, or child theme, we want to remove this stylesheet from being loaded.

    This can be achieved with the wp_dequeue_style function, and by making sure it runs at a lower priority (higher number) than the original function. The original function did not have a priority set, so it will use the default value of 10, so we just need a value of 11 to run later.

    add_action( 'wp_enqueue_scripts', 'mywptheme_child_deregister_styles', 11 );
    function mywptheme_child_deregister_styles() {
    	wp_dequeue_style( 'mywptheme' );
    
    }
    

    Take note that we are using the same style handle as the original registration used.

You must log in before being able to contribute a note or feedback.