David Robertson
David Robertson

Reputation: 77

How to completely dequeue parent theme CSS in Wordpress

There's a bunch of css in my parent theme I don't need and instead of just overwriting it all, I'd like to dequeue it completely and put most of the CSS from the parent theme into the child themes css file.

Is this possible?

Upvotes: 1

Views: 3304

Answers (2)

Argus Duong
Argus Duong

Reputation: 2654

  1. You should identify your styles/scripts handle name before dequeue it. A easiest way is install Query Monitor plugin and see in Styles tab. Handle name is in second column.

    With this plugin, you also see CSS files are required by any dependants.

Query Monitor

  1. Dequeue your CSS:

Append this code to the end of your theme's functions.php file:

    function tdt_dequeue_styles(){
        wp_dequeue_style('your-handle-name');
        wp_deregister_style('your-handle-name');

        // Another style dequeue
        wp_dequeue_style('your-2nd-handle-name');
        wp_deregister_style('your-2nd-handle-name');
    }
    add_action( 'wp_print_styles', 'tdt_dequeue_styles', 9999 );

Upvotes: 1

Neil VanLandingham
Neil VanLandingham

Reputation: 1086

  1. First you'll need to identify the names/handles that the parent theme's stylesheets were originally enqueued under. You can do this quickly by running a search on your web server in the parent theme directory, e.g. grep wp_enqueue_style /var/www/mysite/wp-content/themes/parent_theme/
  2. Then add a dequeue function to the child theme's functions.php file, and initialize it with a priority higher than the priority level set for the parent theme's enqueue function:

    function remove_parent_styles() {
        wp_dequeue_style( 'name_of_parent_stylesheet' );
        wp_dequeue_style( 'name_of_parent_stylesheet_2' );
    }
    add_action( 'init', 'remove_parent_styles', 99 );
    

Upvotes: 1

Related Questions