How can i disable all js files from plugins and load one single js file which i have combined and compressed ?

Is there any way ?


You could install a plug-in like asset Queue Manager to keep track of all the active stylesheets and javascript files (it's preaty neat, you can live-preview how the page would look without an asset to see if your site gets broken or not), and then in your theme's functions.php file, put a code like the following

add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );
function my_deregister_javascript() {
  foreach ($deregistered_scripts as $key => $script) {
    wp_deregister_script( $script );

(of course you may want to replace the $deregistered_scripts array with only the ones that you won't be using)

If your blog is in development mode and you find an error message after this, some plug-in might be causing the issue. Try adding an @ to the line 250 of /wp-includes/class.wp-scripts.php (it worked for me to solve an error warning woocommerce was throwing)

public function set_group( $handle, $recursion, $group = false ) {
        if ( @$this->registered[$handle]->args === 1 ) //"@" added
            $grp = 1;
            $grp = (int) $this->get_data( $handle, 'group' );

        if ( false !== $group && $grp > $group )
            $grp = $group;

        return parent::set_group( $handle, $recursion, $grp );

Edit: the deregistering-scripts code was addapted from this blog article by Justin Tadlock

  • Been using asset queue manager for a few months now... Very useful. Just came across a similar one that is also awesome, with the advantage of letting you dequeue scripts on individual pages/posts. – Bryan Willis Mar 5 '16 at 23:10

Similar to the first answer, but this should work

function remove_all_scripts() {
   foreach( wp_scripts()->registered as $script ) {
      wp_dequeue_script( $script );
      wp_deregister_script( $script );
add_action('wp_enqueue_scripts', 'remove_all_scripts', PHP_INT_MAX);
  • 2
    You should dequeue and deregister to completely remove scripts and styles. Also, your priority should also be correct, probably a priority like PHP_INT_MAX will be useful here – Pieter Goosen Mar 6 '16 at 6:44
  • I'm not sure if the wp_script_is part is neessary... what do you think Pieter? Also, using PHP_INT_MAX is a great idea. I never have thought to do that before. Is there any downsides to using that ever? – Bryan Willis Mar 6 '16 at 10:18
  • I'm not sure if the wp_script_is part is neessary No, not necessary, wp_script_is() is useful if you need to check if a script already exists and is currently registered/enqueued/etc to avoid conflict when you add your own scripts. As for PHP_INT_MAX, it is useful to make sure that your action runs dead last, specially when you need to remove like in this case – Pieter Goosen Mar 6 '16 at 10:28
  • 1
    Ok cool so it's ok to dequeue a script if it hasn't been enqueued? – Bryan Willis Mar 6 '16 at 10:30

You can try to do something like this:

add_action( 'wp_enqueue_scripts', 'wpse8170_disable_all_scripts', 9999 );
function wpse8170_disable_all_scripts() {
    global $wp_scripts, $wp_styles;

    $wp_styles = new WP_Styles(); // reset all styles
    $wp_scripts = new WP_Scripts(); // reset all scripts

But pay attention that this is bad habit to do what you want to do and could lead to unexpected results in the future.

  • will this also disable wordpress core js files from wp-includes – luckyrajiv Oct 15 '13 at 10:04
  • i just want to disable all js and css from plugins and theme files – luckyrajiv Oct 15 '13 at 10:04
  • yes, it has to clear all already enqueued scripts and styles – Eugene Manuilov Oct 15 '13 at 10:08
  • This does keep the core scripts/styles - however it will not remove anything registered (or enqueued directly) after wp_enqueue_scripts. – Stephen Harris Aug 19 '15 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.