我正在尝试将不同的css文件排入队列,具体取决于我使用的页面模板。
从wp_enqueue_scripts动作函数调用的函数is_page_template(“index.php”)(其中调用所有样式和脚本)始终返回false。我确信我使用的是index.php模板 - 它也被“What the file”插件报告为工作模板。
关于将脚本添加到html标题,获取页面模板的方法是什么?
function the_scripts() {
if( is_page_template('index.php') ) {
print "this is index.php";
} else {
print "failed";
}
}
wp_enqueue_style( [style_1], [path_1] );
...
wp_enqueue_style( [style_n], [path_n] );
}
add_action( 'wp_enqueue_scripts', 'the_scripts' );
答案 0 :(得分:0)
我认为(is_page()&&!is_page_template())将在wp_enqueue_scripts挂钩中工作,以检查默认页面模板是否正在使用中。