I'm following some of the other people's advice here about adding my js file before the closing body tag but it doesn't seem to work for me.
If someone would be so kind as to check this for me please?
<?php
/*load the js file into the footer*/
function myscript()
{
if( wp_script_is( 'jquery', 'done' ) ) {
?>
<script type="text/javascript" src="js/scripts.js"></script>
<?php
}
}
add_action( 'wp_footer', 'myscript' );
?>
Many thanks
EDIT:------------------------------------------------
This is the short solution..
<script language="javascript" src="<?php bloginfo('template_directory'); ?>/js/scripts.js"></script>
not the right answer though is it?
EDIT---------------------------------------------------
This is what I am trying based on the WP codex examples and your points Fischi but think I am still doing something wrong..
function my_scripts_method() {
wp_enqueue_script(
'myscript',
get_bloginfo('template_directory') . '/js/scripts.js',
array( 'jquery' ),
'',
true
);
}
add_action('wp_enqueue_scripts', 'my_scripts_method');
The file still doesn't load into the footer.
<script>
tags don't appear in the footer - or is the script is not being found?. Finally does your theme callwp_footer();