[Support request] child theme stylesheet enqueue order to override plugin

Home Forums Support [Support request] child theme stylesheet enqueue order to override plugin

Home Forums Support child theme stylesheet enqueue order to override plugin

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1297004
    Gary

    hello,

    i am building our site with Generatepress using the Divi Builder plugin. I’ve created a child theme using the Generatepress child theme. it appears the Divi plugin stylesheet is overriding the all.min.css stylesheet and simple styling in our gutenberg blocks (like HR and UL/LI order lists) are getting overridden by the divi plugin. it looks like the divi stylesheet is loaded after the all.min.css. Is there a recommended way to change the enqueue order in child theme to get the plugin css to load first and then parent/child stylesheets?

    I’ve attempted this and it loads the divi frontend-builder styles before my child theme styles, but still after the parent theme style (assuming its all.min.css). I also seems to load the plugin and my child theme stylesheets twice 🙁

    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles', 999 );
    function my_theme_enqueue_styles() {
    	$the_plugin = 'divi-builder';
    	$the_path = 'includes/builder/styles/frontend-builder-plugin-style.unified.css';
        $parent_style = 'generate-style'; // This is 'generatepress' for the GeneratePress theme.
    	$parent_style2 = 'frontend-builder-plugin-style'; // This is 'divi-builder' style for the divi builder plugin.
    	
    	// wp_dequeue_style( 'frontend-builder-plugin-style' );
    	// wp_dequeue_style( 'generatepress-child' );
    	wp_enqueue_style( $parent_style2, plugins_url( $the_path, $the_plugin ), array(), wp_get_theme()->get('Version'));
        wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' , array(), wp_get_theme()->get('Version'));
    
    	wp_enqueue_style( 'generatepress-child',
    		get_stylesheet_directory_uri() . '/style.css',
            array($parent_style2,  $parent_style),
            wp_get_theme()->get('Version')
        );
    }

    any help would be much appreciated!

    #1297309
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Assuming divi-builder is the handle, you could try this:

    add_action( 'wp_enqueue_scripts', function() {
        wp_dequeue_style( 'divi-builder' );
    }, 99 );
    
    add_action( 'wp_enqueue_style', function() {
        wp_enqueue_style( 'divi-builder-moved', 'PATH TO DIVI STYLE' );
    }, 0 );
    #1363498
    Craig

    Just curious if this ever got resolved. I am running into a similar issue. Its like every plugin I use Divi overrides the css and messes it up. If I just used Generatepress sections the plugins work fine. But with Divi Builder, having a real hard time. I tried the php above but didnt seem to work for me.

    #1363628
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    You may need to ask them if it’s possible to load their CSS earlier. I’m not sure if my code above works, unfortunately.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.