[英]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.