Remove plugin JS or CSS – WordPress methods

Remove plugin JS or CSS - WordPress methods

Remove plugin JS or CSS – WordPress methods


Making a WordPress site without using any plugin is near to impossible and unimaginable, because WordPress plugins are great ready-made code libraries which can built features for you with just single click. WordPress plugins are exists for extra functionality.

There are bunch of plugins are available almost for any of the web development needs some of them are available freely and some of them are premium where you have to buy plugin if you like to use. Many WordPress plugins having their own styles and scripts in form of CSS and JS. These plugins inject javascripts and stylesheets into the pages where the plugin features used.

If you are not planning to add custom styling for pages/elements created by plugin then there is no problem. Also the plugin is specially designed for back-end like WP Show Stats to see various stats about how different WP elements used on your site. But if you already applied styles to other pages and your own styles conflict with plugin styles or javascripts then you will need to identify that and resolve conflicts between them. Here you will sometime need to remove javascripts and specially stylesheets added by plugin.

If you like to find any stylesheets or javascripts added to your page then you can identify from your webpage source (right click on any page and click on View Source). There you can see stylesheets and javascripts added by plugins you installed in footer area or in header area.

Ways to remove plugin js or css

1. De-register – Remove plugin js or CSS

Remove plugin js or css using wp_deregister_script() and wp_deregister_style() methods. The option will work most of times.

function remove_unwanted_scripts_styles() {
// deregister styles
wp_deregister_style('unwanted_css'); // stylesheet name
// deregister scripts
wp_deregister_script('unwanted_js'); /javascript name
}

add_action('wp_footer', 'remove_unwanted_scripts_styles');

2. Remove plugin js or css by removing action

If deregister methods not working for you then you can try by removing action. Some plugin are not built with recommended way as styles and js are not included with wp_enqueue methods. Then you can use remove_action() method.

remove_action('wp_head', 'unwanted_js');

It is very tedious task when you have additional styles or scripts loaded from any plugin and that messing up the content on your site. Sometimes even deregistering them is not enough as well. If methods shown above to remove plugin js or css then feel free to ask for help using comments and I will try best to help you in resolving issues.

More reference:

https://codex.wordpress.org/Function_Reference/remove_action

https://codex.wordpress.org/Function_Reference/wp_deregister_script

https://codex.wordpress.org/Function_Reference/wp_deregister_style

No Comments (0)

Speak Your Mind

+ fifty two = fifty nine