0

A plugin vendor I'm getting support from recently suggested that if I didn't want a certain Javascript file within the plugin to be enqueued, I should go into the plugin's files and comment out the enqueueing. However, this will potentially have to be repeated each time I update the plugin. Is there a way to un-enqueue a plugin's script from functions.php in my child theme so that the change will "stick"?

1
  • If you know the handle of the script you could try using the wp_dequeue_script() function -which is what "intertainment for you" below seems to be suggesting- to remove it. However, if the plugin uses OOP code then it might be a little more difficult. You'd need to provide more details so we can help. Commented Apr 26, 2022 at 13:33

3 Answers 3

1

Yes there is, the native WordPress function is called wp_dequeue_script.

Remove a previously enqueued script.

@see https://developer.wordpress.org/reference/functions/wp_dequeue_script/

Example

add_action( 'init', function () {
    wp_dequeue_script( 'jquery-ui-core' );
} );
Sign up to request clarification or add additional context in comments.

1 Comment

This should work, but it looks like the plugin developer did not provide a proper handle to reference. I've decided to report the issue to the developer and wait for them to update their plugin to include a handle.
1

Use

add_action( 'wp_enqueue_scripts', 'my_custom_scripts', 100 );
function my_custom_scripts()
{
    wp_dequeue_script( 'parent-script-handle' );
    wp_deregister_script( 'parent-script-handle' );
}

Works on parent and child theme

Comments

-3
function wp_dequeue_script( $handle ) {
    _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
 
    wp_scripts()->dequeue( $handle );
}

3 Comments

You can't re-register a native function.
Remove a previously enqueued script. @see developer.wordpress.org/reference/functions/wp_dequeue_script add_action( 'init', function () { wp_dequeue_script( 'jquery-ui-core' ); } );
The code copied in this documentation is what the wp_dequeue_script() function does, not what you should write in order to make it work. Adding this code to your functions.php file will result in errors because this function already exists.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.