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');
To include an external JavaScript file, we can use the script tag with the attribute src . You've already used the src attribute when using images. The value for the src attribute should be the path to your JavaScript file. This script tag should be included between the <head> tags in your HTML document.
You need to copy the following code and add it to your functions. php, in a site-specific plugin, or by using a code snippets plugin. If you only want to add JavaScript to a single WordPress post, then you will need to add conditional logic to the code. add_action( 'wp_head' , 'wpb_hook_javascript' );
You can add custom JavaScript to your WordPress site either by using a plugin or by editing your theme or child theme's functions. php file. Using a plugin is the recommended technique if you don't want to edit your source files, as these plugins ensure that your custom scripts load in the right order.
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' );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With