wp_dequeue_style( string $handle )
Removes a previously enqueued CSS stylesheet.
Contents
Description
See also
Parameters
-
$handle
string Required -
Name of the stylesheet to be removed.
Source
File: wp-includes/functions.wp-styles.php
.
View all references
function wp_dequeue_style( $handle ) {
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
wp_styles()->dequeue( $handle );
}
Changelog
Version | Description |
---|---|
3.1.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
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:
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 of10
, so we just need a value of11
to run later.Take note that we are using the same style handle as the original registration used.
The function
wp_dequeue_style()
cannot dequeue the handle that is in dependencies list.For example: I have enqueue this.
If I try to dequeue the handle name
wpdocs_otherplugin_style
, then it will not work.The handle name
wpdocs_otherplugin_style
will be enqueue anyway.Top ↑
Feedback
If you have dependent style you can do following: 1. Check if “dependent” style is loaded at all, and then if it is loaded: 1.1. You dequeue “dependent” style 1.2. OPTIONAL – deregister it so you can enqueue it separately if needed 1.3. Enqueue it as independent 1.4. Dequeue “parent style” 1.5. Enqueue “parent style” again so it is “moved down” toward section and eventually loaded last… 2. ELSE – “dependent” style is NOT loaded 2.1. Just dequeue “parent style” so you can manipulate it’s “load position” 2.2. Enqueue “parent style” again so it is “moved down” toward section and eventually loaded last — By peterbra —