好了,這是我functions.php文件:我該如何使用wp_enqueue_script?
function mdg_setup_scripts() {
wp_register_script('hoverIntent', get_bloginfo('template_url').'/js-custom/hoverIntent.js', array('jquery'));
wp_enqueue_script('hoverIntent');
wp_register_script('mdMenuAnimation', get_bloginfo('template_url').'/js-custom/mdMenuAnimation.js', array('jquery'));
wp_enqueue_script('mdMenuAnimation');
}
add_action('wp_enqueue_scripts', 'mdg_setup_scripts');
這是我本來有:(被編輯過的版本,利用下面冷靜的回答,我離開原來的事後以下
function mdg_setup_scripts() {
wp_register_script('hoverIntent',
get_bloginfo('template_url') . '/js/hoverIntent.js',
array('jquery'),
false,
true);
wp_register_script('mdMenuAnimation',
get_bloginfo('template_url') . '/js/mdMenuAnimation.js',
array('jquery', 'hoverIntent'),
false,
false);
if (!is_admin()) {
wp_enqueue_script('mdMenuAnimation');
}
}
add_action('init', 'mdg_setup_scripts');
的js文件存在於指定的文件夾中。 但根本沒有的JavaScript加載在前端。 我做錯了什麼,但什麼? 我需要註冊的jQuery(我認爲WP雖然有jquery,但)? 我是否編輯分開隊列調用?我需要添加一些東西到我的header.php?
注意:我很抱歉花了我一個星期才把更多的東西放在這裏,我不得不遷移它所在的服務器,同時尋找一份工作。 –