deregister scripts on certain page

You have a basic mistake in your code. The following code

if ( !is_page('my-page') ) {

means that if you are not on that page, deregister the scripts. Have a look at the php operators

! ->  Not !$x True if $x is not true

Also, why not exclude this specific page when you initially enqueue these scripts, something like

add_action( 'wp_enqueue_scripts', 'my_register_javascript', 100 );

function my_register_javascript() {
   if ( !is_page('my-page') ) {

       // ENQUEUE/REGISTER SCRIPTS

     }
}

It is much cleaner and more efficient. I don’t see the point in registerring a script and deregister it again. Rather register the scripts conditionally from the start

Leave a Comment