Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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 ?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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 );
share|improve this answer
add comment

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');
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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