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

Home Forums Support child theme stylesheet enqueue order to override plugin

Viewing 2 posts - 1 through 2 (of 2 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 );
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.