DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for How to remove extra css in wordpress?
Chetan Rohilla
Chetan Rohilla

Posted on • Originally published at readymadecode.com

How to remove extra css in wordpress?

Some times we need to remove some css from our wordpress website or blog to speed up our website. Here below is a trick which you can use to remove unused css from your wordpress website.

First of all you have to find the stylesheet file which you want to remove and to find this open your webpage in google chrome and press ctrl+u to view the source code of the webpage, then find the link tag of css file and there you will see the id in the link tag and this is what you need to remove the css. Now paste the code given below in your functions.php file located at root_directory_path/wp-content/themes/your_theme/functions.php

And we have used here two wordpress core functions wp_dequeue_style and wp_deregister_style.

Here β€˜wc-block-style’ is the id of the link tag which you have found in source code of webpage. You can also see the image below to find id of css.

remove extra css in wordpress

function dequeue_my_css() {

    if (is_home() == true || is_single() == true) {

        wp_dequeue_style('wc-block-style');
        wp_deregister_style('wc-block-style');

    }

}
add_action('wp_enqueue_scripts','dequeue_my_css', 9999);
add_action( 'wp_head', 'dequeue_my_css', 9999 );
Enter fullscreen mode Exit fullscreen mode

Please like share subscribe and give positive feedback to motivate me to write more for you.

For more tutorials please visit my website.

Thanks:)
Happy Coding:)

Top comments (0)

🌚 Friends don't let friends browse without dark mode.

Sorry, it's true.