javascript 在wordpress中添加外部javascript文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28185526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 08:32:11 来源:igfitidea点击:
Add external javascript file in wordpress
提问by user3176335
I want to add more than one external javascript files in wordpress theme, I have found code for adding one file, but I need to add more javascript files. How can I do it?
我想在 wordpress 主题中添加多个外部 javascript 文件,我找到了添加一个文件的代码,但我需要添加更多的 javascript 文件。我该怎么做?
function wpTan_scripts() {
wp_register_script('app', '/js/app.js', false);
wp_enqueue_script( 'app' );
}
add_action('wp_enqueue_scripts', 'wpTan_scripts');
回答by Azeem Hassni
you can add as many scripts as you want.
您可以根据需要添加任意数量的脚本。
function themeslug_enqueue_script() {
wp_enqueue_script( 'jquery-v-2', 'http://code.jquery.com/jquery-2.1.3.min.js', false );
wp_enqueue_script( 'mycustomJs', 'file_name.js', false );
// here you can enqueue more js / css files
}
add_action( 'wp_enqueue_scripts', 'themeslug_enqueue_script' );