not_a_generic_user
not_a_generic_user

Reputation: 2178

How can I override or remove a plugin's CSS from my wordpress page?

Though I can certainly delete the files or references to them in the plugin code, this is not futureproof when I made plugin updates. They say that if I create a copy of their frontend.css file in my {theme}/{pluginname}/css folder, it will override theirs, but that doesn't work.

So I'm left with a style that takes priority because it matches on one of their containers and overrides my default page links.

For example:

.somecontainer a {
    color:red
}

I need it gone. Preferably in a way that doesn't use !important or me specifying another instance of the same to override the values because then I have to manage the colors and styles in my original CSS AND in the override.

I already found code to print all enqueued styles and there were none so I can't just unqueue it.

Upvotes: 1

Views: 1739

Answers (2)

not_a_generic_user
not_a_generic_user

Reputation: 2178

The answer was apparently to DEqueue their styles at the same time I enqueued mine. Not sure why... seems like that would create problems, but this worked:

function my_style() {
    wp_dequeue_style( 'pmpro_frontend' );
    wp_dequeue_style( 'pmpro_print' );
    wp_enqueue_style( 'my-style', get_bloginfo('stylesheet_url') );
}
add_action('wp_enqueue_scripts', 'my_style', 11 );

Upvotes: 2

Neil VanLandingham
Neil VanLandingham

Reputation: 1086

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

    function remove_plugin_styles() {
        wp_dequeue_style( 'name_of_plugin_stylesheet' );
        wp_dequeue_style( 'name_of_plugin_stylesheet_2' );
    }
    add_action( 'wp_enqueue_scripts', 'remove_plugin_styles', 99 );
    

Upvotes: 0

Related Questions