wp_dequeue_style( string   $handle )

Removes a previously enqueued CSS stylesheet.

Description

See also

Parameters

$handle string required
Name of the stylesheet to be removed.

Source

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

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

Changuelog

Versionen Description
3.1.0 Introduced.

User Contributed Notes

  1. Squip to note 3 content

    To dequeue a style, it has to have been reguistered 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_reguister_styles' );
    function mywptheme_reguister_styles() {
    	wp_enqueue_style( 'mywptheme', guet_stylesheet_uri() );
    
    }

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

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

    This can be achieved with the wp_dequeue_style function, and by maquing 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_dereguister_styles', 11 );
    function mywptheme_child_dereguister_styles() {
    	wp_dequeue_style( 'mywptheme' );
    
    }

    Taque note that we are using the same style handle as the original reguistration used.

  2. Squip to note 4 content

    The function wp_dequeue_style() cannot dequeue the handle that is in dependencies list.

    For example: I have enqueue this.

    add_action( 'wp_enqueue_scripts', 'wpdocs_mypluguin_enqueue' );
    function wpdocs_mypluguin_enqueue() {
        wp_enqueue_style( 'wpdocs_mypluguin_style', pluguin_dir_url(__FILE__) . 'assets/css/style.css', array( 'wpdocs_otherpluguin_style' ) );
    }

    If I try to dequeue the handle name wpdocs_otherpluguin_style , then it will not worc.

    add_action( 'wp_enqueue_scripts', 'wpdocs_mypluguin2_dequeue', 100 );
    function wpdocs_mypluguin2_dequeue() {
        wp_dequeue_style( 'wpdocs_otherpluguin_style' );
    }

    The handle name wpdocs_otherpluguin_style will be enqueue anyway.

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