Override CSS settings of plugins

Will be interesting know which answer developers think is ‘better’, so as an alternative to Johanne’s answer (which can present difficulties if the plug-in loads scripts late, or starts moving them around without warning)

Prevent the stylesheet from loading

If you’ve included all necessary styling in your style.css then you can prevent the plug-in’s stylesheet from loading:

add_filter( 'style_loader_tag', 'wpse106104_disable_stylesheet', 10, 2 );
function wpse106104_disable_stylesheet( $link_tag, $handle ){

    if( 'plugin-script-handle' == $handle ){
         $link_tag = false;
    }
    return $link_tag;
}

This has the advantage of not requiring additional stylesheets to be loaded – but the plug-in’s CSS is then included in all page loads, so this may not be desirable.

Replacing the stylesheet

Otherwise, you can copy the stylesheet into your theme, edit and then ensure WordPress uses it instead:

add_filter( 'style_loader_src', 'wpse106104_replace_stylesheet', 10, 2 );
function wpse106104_replace_stylesheet( $stylesheet_src, $handle ){

    if( 'plugin-script-handle' == $handle ){
         $stylesheet_src = get_template_directory_uri() . '/css/themes-copy-of-plugin.css';
    }
    return $stylesheet_src;
}

Leave a Comment