Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Actually i have one theme with enqueue for insert jquery code and reference for the core and also jquery iu

Bus happend things that i don´t understad, actually as i tell until i need insert code for create slide of images , simple slide with popular plugin which works perfect in single pages

For this i create simple shortcode and show images and this move into slide

When i create the shortcode this show the images but no move , i see if the code of plugin load in the DOM and i see the perfect reference and the reference also to the core of jquery inside the head in the theme and when load the page

I see one time and other time and the slider no works , finally i put the reference remote code of jquery inside the content ofr shortcode and finally the scrip of slider works but all jquery code of the rest of my blog , never more works and in the dom i see 2 calls to load jquery core

I don´t understand if i see in the head - in the DOM - the reference to general core of jquery , why no works the scripts all , because in the DOM i see this jquery core and all scripts mus works perfectly , if the core load , but also works if core of jquery it´s until inside the shortcode

How it´s possible

Sorry i hope understand all regards

For example this , only works the codes about this plugin if until put the call to remote core of jquery and if no , no load nothing and this core code really load in the head .....

wp_enqueue_script('jquery-cycle',  TEMPLATE_PATH . '/js/jquery.cycle.all.js', array('jquery'), null );

For no get problems i create this but continue the problems :

function fix_noconflict() {
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery' , 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js' );
}
add_action( 'wp_enqueue_scripts' , 'fix_noconflict' );
share|improve this question
add comment

1 Answer

Best practise while developing a Wordpress theme is to always use the jquery included in WP. So deregister it and use a cdn hosted version should be avoided.

This is a required practise, e.g. to include themes in wordpress repository and also some famous themes marketplaces (like themeforest) at this time do not accept themes that use a cdn hosted version of jQuery.

After that, your code:

wp_enqueue_script('jquery-cycle',  TEMPLATE_PATH . '/js/jquery.cycle.all.js', array('jquery'), null );

is a bit wrong, because TEMPLATE_PATH return the path of the theme, but wp_enqueue_script need the url. Another problem is that wp_enqueue_script should be called using the wp_enqueue_scripts action hook (admin_enqueue_scripts for backed). See here

So you should replace previous code with:

add_action('wp_enqueue_script', 'enqueue_my_scripts');

function enqueue_my_scripts() {
  wp_enqueue_script('jquery-cycle',  get_template_directory_uri() . '/js/jquery.cycle.all.js', array('jquery'), null );
}

Note how I've used the add_action function to hook into wp_enqueue_script action and how inside the function I've used get_template_directory_uri function to retrieve the url of the theme root folder.

See here docs for add_action, here docs for the wp_enqueue_script hook and here docs for get_template_directory_uri.

From codex, in the wp_enqueue_script docs page (link) you can read

The jQuery library included with WordPress is set to the noConflict() mode (see wp-includes/js/jquery/jquery.js). This is to prevent compatibility problems with other JavaScript libraries that WordPress can link.

So every script that use jquery in wordpress must be wrapped in one of the noConflict wrappers. For example, if you want ot use this code (example taken from jquery cycle docs):

$('#shuffle').cycle({ 
    fx:     'shuffle', 
    easing: 'easeOutBack', 
    delay:  -4000 
})

you need to wrap it with noConflict wrapper, so it should be:

jQuery(document).ready(function($) {

    $('#shuffle').cycle({ 
        fx:     'shuffle', 
        easing: 'easeOutBack', 
        delay:  -4000 
    })

});

Probably in your code you have used, the $ jQuery shortcut directly and for this reason it doesn't work.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.