[英]Wordpress - loading custom css on index.php
我正在嘗試加載index.php的自定義布局樣式。 我的主題稱為kendo,我正在嘗試在functions.php中提取一些自定義樣式表
樣式表是分開工作的(例如,如果我刪除一行),但它們會相互覆蓋。 我的代碼有問題嗎?
function kendo_scripts() {
wp_enqueue_style( 'kendo-style', get_stylesheet_uri() );
if (is_page_template('index')) {
wp_enqueue_style( 'kendo-layout-style1', get_template_directory_uri() . '/layouts/no-sidebar.css' );
}
if (!is_page_template('index')) {
wp_enqueue_style( 'kendo-layout-style2', get_template_directory_uri() . '/layouts/content-sidebar.css' );
}
您為is_page_template
掛鈎使用了錯誤的參數。 使用帶有擴展名的完整模板文件名。 index.php
不是index
。
這是可能的問題。 示例代碼:
/*Add Hook*/
add_action( 'wp_enqueue_scripts', 'kendo_scripts' );
/*Define the callback*/
function kendo_scripts() {
wp_enqueue_style( 'kendo-style', get_stylesheet_uri(), array(), null, 'all' );
if ( is_page_template( 'index.php' ) ) {
wp_enqueue_style( 'kendo-layout-style1', get_template_directory_uri() .'/css/bootstrap.min.css', array(), null, 'all' );
} else {
wp_enqueue_style( 'kendo-layout-style2', get_template_directory_uri() . '/layouts/content-sidebar.css', array(), null, 'all' );
}
}
不會將其添加到header.php更容易...
<?php if (is_front_page()) { ?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/css/stylesheet1.css"/>
<?php } else { ?>
<link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory'); ?>/css/stylesheet2.css"/>
<?php } ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.