Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add external javascript file in wordpress

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');
like image 569
user3176335 Avatar asked Jan 28 '15 05:01

user3176335


People also ask

How do I include an external JavaScript file?

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.

How do I add JavaScript to WordPress without plugins?

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

Can you embed JavaScript in WordPress?

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.


1 Answers

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' );
like image 130
Azeem Hassni Avatar answered Oct 03 '22 06:10

Azeem Hassni