Add external javascript file in wordpress

元气小坏坏 提交于 2021-02-20 06:47:09

问题


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?

function wpTan_scripts() {
   wp_register_script('app', '/js/app.js', false);
   wp_enqueue_script( 'app' );
}
add_action('wp_enqueue_scripts', 'wpTan_scripts');

回答1:


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' );


来源:https://stackoverflow.com/questions/28185526/add-external-javascript-file-in-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!