WP enqeue script

In your header file call the wp_enqueue_script before wp_head, like this:

<?php wp_enqueue_script( 'jquery' ); ?></p>
<p><?php wp_head(); ?>

And then put all your javascript code after wp_head.

You can give this function another name but don’t use “my_init_method” because this will conflict with other WP functions.

The only thing you have to do now is to call your javascript using the no-conflict mode. This means that you can’t call the script using the $ shortcode but like this:

jQuery(document).ready(function({<br />
// stuff<br />

Code Snippet:

function your_init_yourscript() {
    wp_deregister_script( 'jquery' );
    wp_register_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js');
add_action('init', 'your_init_yourscript');

Posted in Pure hacks