user3169905
user3169905

Reputation: 199

Is there a way to un-enqueue a WordPress plugin's script within functions.php?

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"?

Upvotes: 0

Views: 1857

Answers (3)

fearis
fearis

Reputation: 499

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

Upvotes: 1

amarinediary
amarinediary

Reputation: 5441

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' );
} );

Upvotes: 1

Vipin Singh
Vipin Singh

Reputation: 43

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

Upvotes: -3

Related Questions