I’ve read all the posts and the documentation on wp_enqueue script… but I’ve NEVER successfully gotten it to work.
This is what I’m doing that works:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"</script>
<script type="text/javascript">
MY CODE
</script>
I know I know I know this isn’t the right way to to do it. So here’s what I’ve tried instead:
wp_enqueue_script('jquery');
wp_head();
No luck.
add_action('init', 'addscripts');
function addscripts() {
wp_enqueue_script('jquery');
}
wp_head();
No luck.
//in the theme's functions.php file
add_action('init', 'addscripts');
//add_action('wp_enqueue_scripts', 'addscripts'); //this also doens't work
function addscripts() {
wp_enqueue_script('jquery');
}
I’ve also tried the same approaches with the link to the external jquery library at google instead of the jquery tag. I’ve also tried de-registering and then registering the jquery script. Never works.
So I think these are the key questions:
-
Is there something wrong with my call to the
wp_enqueue_script()function? -
Where should it go?
functions.php?header.php? -
Is there a specific hook that I need to be using that’s not mentioned?
'init'?'template_redirect'?'wp_enqueue_scripts?'?
Please, no copy/pasted snippets from the codex! I’ve read it 50 times and tried them all. I promise.
I’m experimenting with a clean installation of WP3 and adding the above code to the default twentyeleven theme.
We have to assume that wp_enqueue works because I am not seeing pitchforks and torches on the horizon.
Such a thing would upset many developers.
So given that, let’s assume that it’s never being called.
Try adding something like this to the function that’s being called to unregister/register your new version of jQuery (not sure why you want to do this BTW).
Then after you run your site and you expect your function to be called, go check your servers error log (/var/log/apache/yoursite-error.log or something) and see if that string shows up.
If it is showing up, we can move on to the next set of troubleshooting.