How to dequeue or deregister all jquery scripts in wordpress admin panel

I am working on a plugin and in plugin i am using wordpress color picker

color_picker.js:

Read More
jQuery(document).ready(function($){
    jQuery('.cp-field').wpColorPicker();
});

and in index.php file:

add_action('admin_init', 'enqueue_color_picker');
function enqueue_color_picker($hook_suffix) {
    // first check that $hook_suffix is appropriate for your admin page
    wp_enqueue_style('wp-color-picker');
    wp_enqueue_script('cp-script-handle', plugin url.'js/color_picker.js', array( 'wp-color-picker' ), false, true);
}

after that i refresh my admin page and view source it all jquery and jquery-ui scripts load before body tag end like:

<script type='text/javascript' src='http://site_url/wp-admin/load-scripts.php?c=1&amp;load%5B%5D=hoverIntent,common,admin-bar,jquery-ui-core,jquery-ui-widget,jquery-ui-mouse,jquery-ui-draggable,jquery-ui-slider,jquery-touch-p&amp;load%5B%5D=unch,iris,wp-color-picker,jquery-ui-sortable,svg-painter,heartbeat,wp-auth-check&amp;ver=4.0'></script>
<script type='text/javascript' src='http://site_url/wp-content/plugins/wp_foo/js/color_picker.js?ver=4.0'></script>

<div class="clear"></div></div><!-- wpwrap -->
<script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script>
</body>

and when i comment color picker function all scripts go.

I want to unload or dequeue or deregister all unwanted scripts. I also try to dequeue or derigster scripts but nothing happen

add_action('admin_init', 'unload_all_jquery');
function unload_all_jquery() {
    //wp_enqueue_script("jquery");
    $jquery_ui = array(
        "jquery-ui-widget",
        "jquery-ui-mouse",
        "jquery-ui-accordion",
        "jquery-ui-autocomplete",
        "jquery-ui-slider",
        "jquery-ui-tabs",   
        "jquery-ui-draggable",
        "jquery-ui-droppable",
        "jquery-ui-selectable",
        "jquery-ui-position",
        "jquery-ui-datepicker",
        "jquery-ui-resizable",
        "jquery-ui-dialog",
        "jquery-ui-button"
    );

    foreach($jquery_ui as $script){
        wp_dequeue_script($script);
    }
}

Any suggestions how can i do this.

Related posts

Leave a Reply

1 comment

  1. In order to “deregister” a script in the admin, you’ll want to hook into the 'admin_enqueue_scripts' hook. This is the hook that is also used to enqueue admin scripts (as the name implies).

    In addition, you’ll need to use wp_deregister_script() instead of wp_dequeue_script(). The reason for this is that the script has been “registered” to the queue, but not actually “enqueued.” So, your final script will look something like:

    add_action('admin_enqueue_scripts', 'unload_all_jquery');
    function unload_all_jquery() {
        //wp_enqueue_script("jquery");
        $jquery_ui = array(
            "jquery-ui-widget",
            "jquery-ui-mouse",
            "jquery-ui-accordion",
            "jquery-ui-autocomplete",
            "jquery-ui-slider",
            "jquery-ui-tabs",   
            "jquery-ui-draggable",
            "jquery-ui-droppable",
            "jquery-ui-selectable",
            "jquery-ui-position",
            "jquery-ui-datepicker",
            "jquery-ui-resizable",
            "jquery-ui-dialog",
            "jquery-ui-button"
        );
    
        foreach($jquery_ui as $script){
            wp_deregister_script($script);
        }
    }