• I’m running a twentysixteen child theme.

    How do I override a plugin css in the child theme?

    Surely there must be a way to override it without editing the plugin css directly in the plugin folder and have it overwritten by the next plugin update?

    I tried Simple Custom CSS. Didn’t help. It loads before the plugin css. I’ve seen this recommended in various places, and maybe it worked in the past, but in the latest WP it doesn’t.

    I tried the below code in my functions.php as recommended elsewhere. Same result.

    add_action( 'wp_enqueue_scripts', 'generate_remove_scripts' );
    function generate_remove_scripts()
    {
        wp_dequeue_style( 'generate-child' );
    }
    
    add_action( 'wp_enqueue_scripts', 'generate_move_scripts', 999 );
    function generate_move_scripts()
    {
        if ( is_child_theme() ) :
            wp_enqueue_style( 'generate-child', get_stylesheet_uri(), true, filemtime( get_stylesheet_directory() . '/style.css' ), 'all' );
        endif;
    }

    I tried the !important tag and it doesn’t help because the plugin css also uses !important for everything.

    And yes, I’m sure the plugin css is being loaded last. Its contents are at the top of the css in chrome developer console, and the other sources such as my theme css and Custom Simple CSS are below it.

    I also tried adding the css underneath wp_head() in the header.css as follows. It still is shown in developer console as loading before the plugin css.

    <?php wp_head(); ?>
    
        <!-- plugin overrides -->
        <link rel="stylesheet" href="http://mysite.com/wp-content/themes/ab/plugin-overrides.css" type="text/css" />
Viewing 2 replies - 1 through 2 (of 2 total)
  • what plugin are you using?

    how does the plugin enqueue or add the styles?

    Thread Starter squeebo

    (@squeebo)

    I’m not sure how it does the styles, but it’s Recent Posts Widget Advanced. I don’t even see a stylesheet in the plugin folder except rpwe-admin.css that just has a few rules for the admin panel I guess.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Override plugin css with child theme css’ is closed to new replies.