Stop theme’s jQuery function from running

We need to know how the script is being enqueued, but if it’s done right, you will be able to remove that .js file using wp_dequeue_script.

How to correctly enqueue scripts

function my_register_script()
    //Registers a script to be enqueued later
    wp_register_script('script-handle', plugins_url('script.js', __FILE__));
}
add_action( 'wp_enqueue_scripts', 'my_register_script', 10);


function my_enqueue_script(){
    //Enqueue the script
    wp_enqueue_script('script-handle');
}
//hook to another action
add_action('other_action', 'my_enqueue_script', 10);

The wp_register_script register the script to be used, passing a $handle (id) and the script $src (url to the script). The wp_enqueue_script adds that script to our page.

It can also happen that the wp_register_script is not used. In that case, the $src is passed to the wp_enqueue_script like this.

wp_enqueue_script('script-handle', plugins_url('script.js', __FILE__));

How to remove a correctly registered script

If the script is enqueued correctly, then you can remove it from your functions.php passing the $handle to wp_dequeue_script.

wp_dequeue_script('script-handle');

Keep in mind that this function should be used after the script has been enqueued, so you should check to which action the wp_enqueue_script is hooked and run the wp_dequeue_script later, hooking it to the same action but with a higher priority.

Following the same example, the wp_enqueue_script is hooked to an action with a $priority of 10, so you should hook the dequeue with a bigger priority

function my_dequeue_script(){
    //Removes the enqueued script
    wp_dequeue_script('script-handle');
}
//hook to another action
add_action('other_action', 'my_dequeue_script', 11);

Where 11 in the add_action function is the $priority (Bigger means later execution)

Do not forget that there may be some scripts that depends of the script you are dequeuing. If thats the case, those scripts won’t load.