我已经成功地将一个js文件添加到WP的functions.php中,并且效果很好。我如何添加另一个?例如,将 classie.js 添加到 add_my_script 函数中?我尝试复制 get_template_directory_uri() 但这不起作用 - 我觉得答案就在我面前!
add_action( 'wp_enqueue_scripts', 'add_my_script' );
function add_my_script() {
wp_enqueue_script(
'slicknav',// name your script so that you can attach other scripts and de-register, etc.
get_template_directory_uri() . '/js/jquery.slicknav.min.js', // this is the location of your script file
array('jquery') // this array lists the scripts upon which your script depends
);
}
最佳答案
您需要调用wp_enqueue_script
两次:
add_action( 'wp_enqueue_scripts', 'add_my_script' );
function add_my_script() {
wp_enqueue_script(
'slicknav',
get_template_directory_uri() . '/js/jquery.slicknav.min.js',
array('jquery')
);
wp_enqueue_script(
'classie',
get_template_directory_uri() . '/js/classie.js',
array('jquery')
);
}
关于javascript - 将多个Javascript文件添加到Wordpress的functions.php中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28282159/