wp_dequeue_style()WP 3.1.0

Remove a previously enqueued CSS stylesheet.

No Hooks.

Return

null. Nothing (null).

Usage

wp_dequeue_style( $handle );
$handle(string) (required)
Name of the stylesheet to be removed.

Examples

0

#1 Removing (dequeue) a style file from the queue

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.

Suppose we have a http://example.com/.../my_style.css style file enqueued to output in HEAD of the HTML code:

add_action( 'wp_enqueue_scripts', 'my_enqueue_style' );

function my_enqueue_style(){
	wp_enqueue_style( 'my_style', get_template_directory_uri() . '/my_style.css' );
}

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

This can be achieved by running wp_dequeue_style() after wp_enqueue_style() and using the same handler my_style. To be sure that we call 'dequeue' function after 'enqueue' let's use later priority for the hook function call. Default value of 10, so we just need a value of 11 to run later.

add_action( 'wp_enqueue_scripts', 'my_dequeue_style', 11 );

function my_dequeue_style(){
	wp_dequeue_style( 'my_style' );
}
0

#2 Style can't be dequeued if it is in dependencies list.

This function cannot dequeue the handle that is in dependencies list.

For example: I have enqueue this.

add_action( 'wp_enqueue_scripts', 'wp_kama_enqueue' );

function wp_kama_enqueue() {
	wp_enqueue_style( 'my_style', plugin_dir_url(__FILE__) . 'assets/css/style.css', [ 'my_style_two' ] );
}

If we try to dequeue the my_style_two style, it will not work and it will be enqueue anyway.

add_action( 'wp_enqueue_scripts', 'wp_kama_dequeue', 100 );

function wp_kama_dequeue() {
	wp_dequeue_style( 'my_style_two' );
}

Notes

Changelog

Since 3.1.0 Introduced.

wp_dequeue_style() code WP 6.5.2

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

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