Usage
nebula()->deregister($handle, $type);
Parameters
$handle
(Required) (String) The handle of the asset to deregister
Default: None
$type
(Required) (String) Whether this asset is a "style" or "script"
Default: None
$indicate
(Optional) (Boolean) Whether to indicate that an asset was dequeued
Default: None
Parameter Notes
The indication that an asset was dequeued is in the admin bar– it will turn yellow and show an icon.
Examples
add_action('wp_enqueue_scripts', function(){ if ( is_front_page() ){ nebula()->deregister('contact-form-7', 'style'); nebula()->deregister('contact-form-7', 'script'); } }, 3000);
Additional Notes
Common WordPress hooks for deregistering assets include wp_enqueue_scripts
, wp_print_styles
, and wp_print_scripts
. Make sure your hook has a higher priority number so it runs after the original.
This function both dequeues and deregisters the asset. Then it logs it in Nebula to appear in the WordPress admin bar (under the Edit Post menu).
Nebula will only show the log when the asset is actually enqueued on a page (otherwise the deregistering has no affect on the page), however, it will still attempt to dequeue and deregister it regardless.
How to find plugins’ asset handles
Use the Nebula search tool in the WordPress Admin Dashboard on the Developer Information metabox to find plugin asset handles. Do a search within an individual plugin for “register_” or “enqueue_” to see what/when they are called. You could also loop through the global $wp_scripts->queue
and $wp_styles->queue
to get a list on an individual page.
Source File
Located in /libs/Optimization.php on line 723.
No Hooks
This function does not have any filters or actions available. Request one?Note: This function contains 1 to-do comment.
public function deregister($handle, $type, $indicate=true){ if ( !empty($handle) ){ //Styles if ( strpos(strtolower($type), 'style') !== false || strpos(strtolower($type), 'css') !== false ){ //@todo "Nebula" 0: Update strpos() to str_contains() in PHP8 //Check if this style was enqueued if ( $indicate && wp_style_is($handle, 'enqueued') ){ $this->deregistered_assets['styles'][] = $handle; //Add it to the array to log in the admin bar } //Deregister the style either way wp_dequeue_style($handle); wp_deregister_style($handle); return true; } //Scripts //Check if this script was enqueued (and show note if so) if ( $indicate && wp_script_is($handle, 'enqueued') ){ $this->deregistered_assets['scripts'][] = $handle; } //Deregister the script either way wp_dequeue_script($handle); wp_deregister_script($handle); return true; } }
Override
This function can not be short-circuited with an override filter. Request one?