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?
Javascript should be placed in footer of html document wherever possible. For libraries like jQuery we don't often have a choice as there may be some other javascript code which depends on that. But we should design site in such a way that maximum javascript code is placed in the end.
Lets assume that your plugin or theme is adding raw JavaScript in the header or between the content. Find the raw JavaScript code in the plugin or theme files, copy the JavaScript and save it in a . js file. Then use wp_register_script() function as shown above, to move JavaScript to the bottom.
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!
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.
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