I accidentally discovered that my child theme CSS is get called twice. I found that this is an old issue (see here and here), but I don’t know how to solve it in my situation.

<link rel="stylesheet" id='parent-style-css'  href="http://infopsi.md/wp-content/themes/twentyseventeen/style.css?ver=4.8.1" type="text/css" media="all" />
<link rel="stylesheet" id='child-style-css'  href="http://infopsi.md/wp-content/themes/twentyseventeen-child/style.css?ver=0.1" type="text/css" media="all" />
<link rel="stylesheet" id='twentyseventeen-style-css'  href="http://infopsi.md/wp-content/themes/twentyseventeen-child/style.css?ver=4.8.1" type="text/css" media="all" />

This is the function that I use to enqueue the parent and child theme stylesheets:

/** Enqueue the parent and child theme stylesheets **/
if ( !function_exists( 'my_theme_enqueue_styles' ) ):
    function my_theme_enqueue_styles() {
        $parent_style="parent-style";
        wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
        wp_enqueue_style( 'child-style',
            get_stylesheet_directory_uri() . '/style.css',
            array( $parent_style ),
            wp_get_theme()->get('Version')
        );
    }
endif;
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );

I tried to add the wp_dequeue_style( 'twentyseventeen-style' ); to the function, but this doesn’t solved the issue. Any suggestions?

1 Answer
1

You don’t need to enqueue your child theme’s stylesheet. The parent theme does that for you. TwentySeventeen has this line:

wp_enqueue_style( 'twentyseventeen-style', get_stylesheet_uri() );

That’s still going to run, but twentyseventeen-style is now your child theme’s stylesheet. You just need to enqueue the parent theme’s stylesheet:

/** Enqueue the parent and child theme stylesheets **/
if ( !function_exists( 'my_theme_enqueue_styles' ) ):
    function my_theme_enqueue_styles() {
        $parent_style="parent-style";
        wp_enqueue_style( $parent_style, get_parent_theme_file_uri( 'style.css' ) );
    }
endif;
add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );

(I swapped your use of the template directory function for get_parent_theme_file_uri() because more people should know about the new theme file functions).

Leave a Reply

Your email address will not be published. Required fields are marked *