John Davidson

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

0 comments
Message:


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



My Answer:
Yes, there is a way to un-enqueue a WordPress plugin. You can do this by using the `wp_dequeue_script()` and `wp_dequeue_style()` functions in your theme's functions.php file. These functions allow you to remove scripts and styles that have been enqueued by a plugin.

For example, if you want to un-enqueue a script called `example-script` that has been added by a plugin, you can use the following code:

php
function remove_example_script() {
wp_dequeue_script('example-script');
}
add_action('wp_enqueue_scripts', 'remove_example_script', 100);


Similarly, if you want to un-enqueue a style called `example-style` that has been added by a plugin, you can use the following code:

php
function remove_example_style() {
wp_dequeue_style('example-style');
}
add_action('wp_enqueue_scripts', 'remove_example_style', 100);


By adding these functions to your theme's functions.php file, you can effectively un-enqueue scripts and styles added by plugins.

Rate this post

3 of 5 based on 7307 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us