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"?
CodePudding user response:
function wp_dequeue_script( $handle ) {
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
wp_scripts()->dequeue( $handle );
}
CodePudding user response:
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' );
} );