好了,这是我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?
注意:我很抱歉花了我一个星期才把更多的东西放在这里,我不得不迁移它所在的服务器,同时寻找一份工作。 –