我想在我的网站主题中添加两个JS文件:
我正在使用的代码:
function wptuts_scripts_with_jquery()
{
// Register the script like this for a plugin:
wp_register_script( 'custom-script', plugins_url( '/js/custom-script.js', __FILE__ ), array( 'jquery' ) );
// or
// Register the script like this for a theme:
wp_register_script( 'custom-script', get_template_directory_uri() . '/js/custom-script.js', array( 'jquery' ) );
// For either a plugin or a theme, you can then enqueue the script:
wp_enqueue_script( 'custom-script' );
}
add_action( 'wp_enqueue_scripts', 'wptuts_scripts_with_jquery' );
通过usnig这个函数,我只能添加一个JS文件,如何添加第二个JS文件。我是wordpress和PHP的新手。需要帮忙!! :)
答案 0 :(得分:0)
function wptuts_scripts_with_jquery()
{
// do this for plugin js
wp_register_script( 'custom-script', plugins_url( '/js/jscripts.js', __FILE__ ), array( 'jquery' ) );
wp_register_script( 'drop-down', plugins_url( '/js/bootstrap-hover-dropdown.js', __FILE__ ), array( 'jquery' ) );
// or this for theme js
wp_register_script( 'custom-script', get_template_directory_uri() . '/js/jscripts.js', array( 'jquery' ) );
wp_register_script( 'drop-down', get_template_directory_uri() . '/js/bootstrap-hover-dropdown.js', array( 'jquery' ) );
wp_enqueue_script( 'custom-script' );
wp_enqueue_script( 'drop-down' );
}
add_action( 'wp_enqueue_scripts', 'wptuts_scripts_with_jquery' );