我拼命讓我的WordPress的enque腳本工作。不知道我做錯了什麼,嘗試了很多,但似乎沒有任何工作。WordPress的if(if_page)和頁面模板不工作
我有一個tittle Ledenlijst,id = 69的頁面。 我只想對該頁面進行排隊。所以我試圖增加到functions.php:
// Funtion to include stylesheet for page ledenlijst.
function enqueue_child_theme_styles() {
wp_enqueue_style('parent-style', get_template_directory_uri().'/style.css');
wp_enqueue_style('child-style', get_stylesheet_uri(), array('parent-style') );
}
// Function to add ledenlijst
function add_ledenlijst() {
wp_enqueue_script(
'your-script',
get_template_directory_uri() . '-child/ledenlijst.js',
array('jquery')
);
}
if(is_page('ledenlijst')){ // Only on ladenlijst page
echo "Page ledenlijst identified"; // debug
// Register Stylesheet
add_action('wp_enqueue_scripts', 'enqueue_child_theme_styles', PHP_INT_MAX);
// Register ledenlijst script
add_action('wp_enqueue_scripts', 'add_ledenlijst');
}
由於某些原因,它不被識別。我也嘗試過: 如果(is__page(69), A已經複製了默認頁面,在我的子主題文件夾中創建了pageLedenlijst.php,將該主題應用到此頁面並嘗試: if(is_page_template('pageLedenlijst.php')
沒有什麼工作,沒有顯示調試中,enque schript將不會加載。
嘗試在函數中添加is_page()代碼,並在諸如「wp_loaded」之類的鉤子中調用它。 – WisdmLabs 2014-10-31 12:43:10