wp_deregister_script

Remove a registered script.

Description

wp_deregister_script( (string) $handle ); 

Note: there are intentional safeguards in place to prevent critical admin scripts, such as jQuery core, from being unregistered.

Parameters (1)

0. $handle (string)
Name of the script to be removed.

Usage

  1. if ( !function_exists( 'wp_deregister_script' ) ) { 
  2. require_once ABSPATH . WPINC . '/functions.wp-scripts.php'; 
  3.  
  4. // Name of the script to be removed. 
  5. $handle = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wp_deregister_script($handle); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/functions.wp-scripts.php  
  1. function wp_deregister_script( $handle ) { 
  2.  
  3. /** 
  4. * Do not allow accidental or negligent de-registering of critical scripts in the admin. 
  5. * Show minimal remorse if the correct hook is used. 
  6. */ 
  7. $current_filter = current_filter(); 
  8. if ( ( is_admin() && 'admin_enqueue_scripts' !== $current_filter ) || 
  9. ( 'wp-login.php' === $GLOBALS['pagenow'] && 'login_enqueue_scripts' !== $current_filter ) 
  10. ) { 
  11. $no = array( 
  12. 'jquery', 'jquery-core', 'jquery-migrate', 'jquery-ui-core', 'jquery-ui-accordion',  
  13. 'jquery-ui-autocomplete', 'jquery-ui-button', 'jquery-ui-datepicker', 'jquery-ui-dialog',  
  14. 'jquery-ui-draggable', 'jquery-ui-droppable', 'jquery-ui-menu', 'jquery-ui-mouse',  
  15. 'jquery-ui-position', 'jquery-ui-progressbar', 'jquery-ui-resizable', 'jquery-ui-selectable',  
  16. 'jquery-ui-slider', 'jquery-ui-sortable', 'jquery-ui-spinner', 'jquery-ui-tabs',  
  17. 'jquery-ui-tooltip', 'jquery-ui-widget', 'underscore', 'backbone',  
  18. ); 
  19.  
  20. if ( in_array( $handle, $no ) ) { 
  21. $message = sprintf( 
  22. /** translators: 1: script name, 2: wp_enqueue_scripts */ 
  23. __( 'Do not deregister the %1$s script in the administration area. To target the front-end theme, use the %2$s hook.' ),  
  24. "<code>$handle</code>",  
  25. '<code>wp_enqueue_scripts</code>' 
  26. ); 
  27. _doing_it_wrong( __FUNCTION__, $message, '3.6.0' ); 
  28. return; 
  29.  
  30. wp_scripts)->remove( $handle );