How to remove all javascript in a theme wordpress?

I have a theme name is mytheme
in themes/mythem/functions.php I using code:

function remove_scripts() {
   remove_action('wp_head','mytheme_head_scripts');
}
add_action('init', 'remove_scripts');

=>but result can’t remove all javascript, how to fix it ?

Related posts

Leave a Reply

2 comments

  1. You either use the admin_*/wp_print_scripts hook or the admin_*/wp_print_styles hook. The styles hook comes before the print scripts hook, so maybe it fits better than just using a priority of 0 for the *_print_scripts hook (there might be function with a name that’s hooked in earlier on priority 0).

    function wpse61635_remove_all_scripts()
    {
        global $wp_scripts;
        $leave_alone = array(
            // Put the scripts you don't want to remove in here.
        );
    
        foreach ( $wp_scripts->queue as $handle )
        {
            // Here we skip/leave-alone those, that we added above ↑
            if ( in_array( $handle, $leave_alone ) )
                continue;
    
            $wp_scripts->remove( $handle );
        }
    }
    add_action( 'wp_print_styles', 'wpse61635_remove_all_scripts', 0 );
    
  2. If the function mytheme_head_scripts used priority while hooking into wp_head then you must set your remove_action with same priority.

    Example –

    function remove_scripts() {
       remove_action('wp_head','mytheme_head_scripts',10);
    }
    add_action('init', 'remove_scripts');