How to put my javascript in the footer

I just want to ask on how to print script ‘javascript’ at the footer using simple plugin. I’m using WordPress 3.0 any ideas?

asked Nov 19 ’10 at 3:37
Trez

40441022

Use a functions.php file inside your theme template add this :

<?php

function add_this_script_footer(){ ?>

[YOUR JS CODE HERE]

<?php } 

add_action('wp_footer', 'add_this_script_footer'); ?>

Hope it helps!

answered Nov 19 ’10 at 15:07
Jk_

6611621

6  
Sweet. Thanks. Additionally, though, if you want to make sure it loads after another script, (ie, JQuery) you can add a priority like so: add_action('wp_footer', 'add_this_script_footer', 20);
– Eric G
Jun 15 ’12 at 20:44
    
To include js code in admin footer, ‘admin_footer’ action can be used.
– sudip
Aug 4 ’13 at 13:25
1  
Thanks @EricG for the 3rd parameter.
– roshan
Dec 27 ’15 at 11:32

For an external javascript file to be linked in the footer, use this (>= WP2.8)

function my_javascripts() {
    wp_enqueue_script( 'the-script-handle', 
                       'path/to/file.js', 
                       array( 'jquery','other_script_that_we_depend_on' ), 
                       'scriptversion eg. 1.0', 
                       true);
}
add_action( 'wp_enqueue_scripts', 'my_javascripts' );

That last true means that the script should be put at the wp_footer() hook.

answered Nov 19 ’10 at 16:14
windyjonas

1,4461016

Hum may be it’s too late to answer, but if anyone else comes here with the same problem :

There is a plugin to do this :
http://wordpress.org/extend/plugins/footer-javascript/

Or you can doing this manually by adding this short code in your functions.php :

/**
 * Automatically move JavaScript code to page footer, speeding up page loading time.
 */
remove_action('wp_head', 'wp_print_scripts');
remove_action('wp_head', 'wp_print_head_scripts', 9);
remove_action('wp_head', 'wp_enqueue_scripts', 1);
add_action('wp_footer', 'wp_print_scripts', 5);
add_action('wp_footer', 'wp_enqueue_scripts', 5);
add_action('wp_footer', 'wp_print_head_scripts', 5);

answered Jul 23 ’12 at 13:28

You can also try this plugin, Scripts To Footerphp

It is compatible with WordPress version 4

answered Nov 29 ’14 at 19:41
Nedudi

2,87512123

http://stackoverflow.com/questions/4221870/how-to-put-my-javascript-in-the-footer

Губарь Маргарита Александровна