最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - Problem with displaying CSS Stylesheets - Am I adding them correctly in my wordpress child theme?

programmeradmin0浏览0评论

Is this a proper way to load CSS files into my WordPress child theme?

add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
add_action( 'wp_enqueue_scripts', 'case_studies_styles' );
add_action( 'wp_enqueue_scripts', 'about_styles' );

function my_theme_enqueue_styles() {
    wp_enqueue_style( 'child-style', get_stylesheet_uri(),
        array( 'parenthandle' ), 
        wp_get_theme()->get('Version') // this only works if you have Version in the style header
    );
}

function case_studies_styles() {
    wp_enqueue_style( 'child-casestudies', get_stylesheet_directory_uri() . '/casestudies.css', array(), rand());
}

function about_styles() {
    wp_enqueue_style( 'child-about', get_stylesheet_directory_uri() . '/about.css', array(), rand());
}

I'm asking because I've asked some people to try to load my site, and some of them don't get the stylesheets at all and just get the blank HTML code.

Also, in the beginning of all CSS files, I have this beginning. Every CSS file has a different version (1.2,1.1,1.0)

/*
 Theme Name:   GeneratePress Child
 Theme URI:    
 Description:  Default GeneratePress child theme
 Template:     generatepress
 Version:      1.2
*/

EDIT: I've tried this too, but still no effect.

function my_theme_enqueue_styles() {
    wp_enqueue_style( 'child-style', get_stylesheet_directory_uri() . '/style.css', wp_get_theme()->get('Version'));
}

function case_studies_styles() {
    wp_enqueue_style( 'child-casestudies', get_stylesheet_directory_uri() . '/casestudies.css', wp_get_theme()->get('Version'));
}

function about_styles() {
    wp_enqueue_style( 'child-about', get_stylesheet_directory_uri() . '/about.css', wp_get_theme()->get('Version'));
}
发布评论

评论列表(0)

  1. 暂无评论