Some of you might know that I've been really struggling with trying to enqueue Javascript to my Wordpress theme and I just can't get it to work. I need to get this done somehow. I will keep this question updated, I will edit and I hope you will work together with me through this step by step! It's been a few months now and I still can't get it to work and I have no clue why!
Step 1:
I want to move all the script calls in my header.php into my function.php. I transfered everything to my function.php: (updated!)
function add_my_javascripts() {
/* If this is the admin area of WordPress, don't do anything */
if( is_admin() )
return;
/* Register all of our scripts */
wp_register_script('jquerytools', 'http://cdn.jquerytools.org/1.2.5/all/jquery.tools.min.js', array('jquery'));
wp_register_script('jquery.form', get_template_directory_uri() . '/js/jquery.form.js', array('jquery'));
wp_register_script('sprinkle', get_template_directory_uri() . '/js/sprinkle.js', array('jquery', 'jquery-ui-core', 'jquery-ui-tabs'));
wp_register_script('custom', get_template_directory_uri() . '/js/custom.js', array('jquery'));
wp_register_script('tooltip', get_template_directory_uri() . '/js/tooltip.js', array('jquerytools'));
wp_register_script('tooltip', get_template_directory_uri() . '/js/sliding_tabs.js', array('jquerytools'));
wp_register_script('contact-form', get_template_directory_uri() . '/js/contact-form.js', array('jquery', 'jquery.form'));
/* Enqueue the ones that need to be enqueued */
wp_enqueue_script('sprinkle');
wp_enqueue_script('custom');
wp_enqueue_script('tooltip');
wp_enqueue_script('sliding_tabs');
wp_enqueue_script('contact-form');
}
add_action('wp_enqueue_scripts', 'add_my_javascripts');
Here's my whole function.php just to make sure that there's not some other mistake that keeps interfering with the wp_enqueue or something: http://pastebin.com/mhCNZbFW Also, I entered the code into my PARENT THEME's function.php! I do not use a function.php for my child theme at all.
And I tried to call the action in my header.php: (UPDATE: Currently NO HOOK at all, also no CALL in my header.php!!)
Result: All the scripts are properly loaded (checked with Firebug), but none of them actually works! Only the "custom.js" works (even without the action being called in the header.php).
Why does this not work? Please help me working through this as it's causing so many problems!
Step2: (RESOLVED) Next step will be to provide no.Conflict wrappers to every jQuery JS (which also doesn't work).
What I already tried: - deactivated all plugins (no effect) - created a function.php for my child theme and moved the code above from the parent theme's function.php there (result: error message
Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'get_my_scripts' was given in /hermes/bosweb25a/b155/ipg.zoomingjapancom/wp-includes/plugin.php on line 405
- tried another theme (TwentyEleven): same issues - I tried to call it like that in the header.php (as that's how it's done in the TwentyEleven theme:
<?php wp_enqueue_script( 'jquery', 'jquerytools', 'jquery-ui-person', 'jqueryform', 'sprinkle', 'custom', 'tooltip' ); wp_head(); ?>
</head>
That also doesn't work ...
LATEST NEWS: See updated function.php code above. I got to work quite a few things now. As for the jquery-form that was needed for the contact.php I just took the direct script call out of the contact.php and put it into its own js file, then wrapped it with a no_Conflict wrapper and now it works just fine! Only thing I'm worried about is whether Wordpress will now load it on every single page although it's only needed on the contact.php??!!
THE ONLY THING THAT IS STILL NOT WORKING is sprinkle.js: Possible reason is that there might be a conflict with the ui-tabs and the jquerytools-ui-tabs. I should do something like this, but don't know where to put it:
<script type="text/javascript" src="jquery-1.6.2.js"></script>
<script type="text/javascript" src="jquery.tools-1.2.6-dev.js"></script>
<!-- must do this before including jquery-ui -->
<script type="text/javascript">
// change name of jquery tools tabs so that jquery UI doesn't barf
jQuery.fn.jtTabs = jQuery.fn.tabs;
</script>
<script type="text/javascript" src="jquery-ui-1.8.14.js"></script>
If you need any further information, please let me know! Here's my website for reference. I just can't do this on my own. Please give me some advice! Anything might help :) Thanks so much in advance!
wp_print_scripts
action instead see if it works..sprinkle.js
it needs no conflict wrapper$(document).ready(function(){ $('#tabvanilla > ul').tabs({ fx: { height: 'toggle', opacity: 'toggle' } });
Still no change. I thought it's better to keep everything in a no-conflict wrapper anyways? I got to work other scripts, but not sprinkle.js and jquery-form.js (please also see my updated question). Thanks :)