How to load wordpress child theme css after parent theme css

前端 未结 2 1600
我寻月下人不归
我寻月下人不归 2021-02-20 16:15

In my wordpress child theme css file loaded before main theme css. My child theme css functions.php file is given below

function my_theme_enqueue_styles(){
  wp_         


        
2条回答
  •  遇见更好的自我
    2021-02-20 16:47

    According to the documentation (https://codex.wordpress.org/Child_Themes), set the parent style as a dependency of the child style, and load it in your functions.php:

    get('Version')
        );
    }
    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
    ?>
    

    Beware though, that some themes use more than one stylesheet. If that occurs, you can add any and all of them to the function like this:

        $parent_style = 'parent-style';
        $parent_style2 = 'other-parent-style';
    
        wp_enqueue_style( $parent_style, get_template_directory_uri() . '/style.css' );
        wp_enqueue_style( $parent_style2, get_template_directory_uri() . '/inc/css/style.css' );
        wp_enqueue_style( 'child-style',
            get_stylesheet_directory_uri() . '/style.css',
            array( $parent_style, $parent_style2 ),
            wp_get_theme()->get('Version')
        );
    

提交回复
热议问题