My child theme CSS get called twice

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 Comment