我正在尝试加载 index.php 的自定义布局样式。我的主题叫做剑道,我正在尝试在 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
Hook 使用了错误的参数。使用带扩展名的完整模板文件名。 index.php
不是 index
。
See function is_page_template reference.
这是可能的问题。示例代码:
/*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' );
}
}
关于php - Wordpress - 在 index.php 上加载自定义 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30524290/