所以我有一個腳本,我只想包含在一個模板文件中。模板文件位於我的子主題中名爲模板的文件夾中。我以爲我可以通過包括如果functions.php的語句,併名字,像這樣針對模板文件做到這一點:is_page_template()在functions.php中不起作用
function header_anim() {
wp_enqueue_script('head', get_stylesheet_directory_uri() . '/js/head.js');
}
if(is_page_template('/templates/home-template.php')) {
add_action('wp_enqueue_scripts', 'header_anim');
}
但是,好像它不承認if語句出於某種原因。
感謝您嘗試,可惜這沒有工作,因爲它沒有在控制檯中吐出任何錯誤,它的怪異。我已經在functions.php中嘗試了很多不同的代碼,但它不會發生。任何其他想法? –