javascript - Wordpress - Loading JS files after footer -
javascript - Wordpress - Loading JS files after footer -
thanks reading,
how load js files after footer instead of beingness in header
example:
<head> <script type="text/javascript"></script> <script type="text/javascript"></script> <script type="text/javascript"></script> </head> changed
</footer> <script type="text/javascript"></script> <script type="text/javascript"></script> <script type="text/javascript"></script> </body> </html> i've tried
wp_register_script( 'cycle', 'http://malsup.github.com/jquery.cycle2.js', '', '', true); wp_enqueue_script( 'cycle' ); wp_register_script( 'site', get_template_directory_uri().'/js/site.js', '', '', true); wp_enqueue_script( 'site' );
the lastly parameter dictates enqueue script, in footer (true) or in header (false - default):
<?php wp_register_script( $handle, $src, $deps, $ver, $in_footer ); ?> you have hook scripts righteously (please follow inline comments):
to hook front-end:
add_action( 'wp_enqueue_scripts', 'function_name' ); to hook admin panel:
add_action( 'admin_enqueue_scripts', 'function_name' ); here's how should proceed:
<?php function themeslug_load_scripts() { //registering scripts, lastly parameter dictate should enqueue //and saying: yes, in_footer wp_register_script( 'cycle', 'http://malsup.github.com/jquery.cycle2.js', array(), '', true); wp_register_script( 'site', get_template_directory_uri().'/js/site.js', array('jquery'), '', true); //we setting dependency - yes depend on jquery - means load jquery first //actually rendering scripts wp_enqueue_script( 'cycle' ); wp_enqueue_script( 'site' ); } add_action( 'wp_enqueue_scripts', 'themeslug_load_scripts' ); or can try:
<?php function themeslug_load_scripts() { //actually rendering scripts wp_enqueue_script( 'cycle', 'http://malsup.github.com/jquery.cycle2.js', array(), '', true ); wp_enqueue_script( 'site', get_template_directory_uri().'/js/site.js', array('jquery'), '', true ); } add_action( 'wp_enqueue_scripts', 'themeslug_load_scripts' ); and, clear browser cache when working javascripts. load page , see page source. it'll thing you. :)
reference:wp_register_script() wp_enqueue_script() javascript wordpress
Comments
Post a Comment