2017-01-09 71 views
1

我想在我的网站上有多个样式。对我来说,这段代码应该可以工作,但如果有人能告诉我为什么它不是那么好!WordPress的多个样式表

if (is_front_page()) { 
     wp_enqueue_style('custom-frontpage', get_template_directory_uri().'/stylee.css'); 
} else{ 
     wp_enqueue_style('custom-frontpage', get_template_directory_uri().'/css/temp.css'); 
} 

这位于我的functions.php

+0

这是位于我的functions.php – Stephen

回答

0

is_front_page()将总是返回false当在functions.php这样使用。你必须使用wp来创建一个钩子来使它工作。之所以不工作的原因是因为当functions.php启动Wordpress不知道查询的内容时,所以它不会知道你是一个页面的类型。试试这个:

add_action('wp', 'check_is_front_page'); 
function check_is_front_page() { 
    if(is_front_page()){ 
     wp_enqueue_style('custom-frontpage', get_template_directory_uri().'/stylee.css'); 
    }else{ 
     wp_enqueue_style('custom-frontpage', get_template_directory_uri().'/css/temp.css'); 
    } 
} 

你可以阅读有关此特定钩here

你可以阅读更多关于钩子以及它们是如何工作的here

+0

@Stephen,不客气。乐于帮助。 – Ionut