0

I'm trying to deregsiter multiple scripts using the following function.

add_action( 'wp_print_scripts', 'my_deregister_javascript', 100 );
function my_deregister_javascript() {
    if ( !is_page(array('order', 'shopping-cart', 'checkout') ) ) {
    wp_deregister_script( 'tcp_scripts' );
}

How do I use this function to deregsiter multiple scripts?

Thanks in advance.

  • 1
    Take a look at this answer for the correct hooks. – kaiser Feb 21 '12 at 16:26
4

First, you're attempting to deregister too late. You need to use wp_enqueue_scripts, rather than wp_print_scripts.

Second, all you need to do is add a call to wp_deregister_script() for each script you need to deregister:

<?php
add_action( 'wp_enqueue_scripts', 'my_deregister_javascript', 100 );
function my_deregister_javascript() {
    if ( !is_page(array('order', 'shopping-cart', 'checkout') ) ) {
        wp_deregister_script( 'tcp_scripts' );
        // If you need to deregister more scripts when
        // this same conditional is true, just add them here
        wp_deregister_script( 'some-script' );
        wp_deregister_script( 'some-other-script' );
    }
    // If you need to deregister other scripts generally,
    // just do so here, outside the conditional:
    wp_deregister_script( 'some-third-script' );
    wp_deregister_script( 'some-fourth-script' );
}
?>
| improve this answer | |

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.