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.

I don't get it why jQuery function is not working. I read on the interned how to load jQuery in wordpress, but with no success. Can anyone help me?

What I did so far: I've put this in header.php inside tags:

<?php wp_enqueue_script("jquery"); ?>

<?php wp_head(); ?>
 <script type="text/javascript" src="<?php bloginfo('template_url'); ?>/wp-includes/js/jquery/slideshow1.js"></script>

css styles used for jquery:

 #gallery1{
 float:right;
 width:400px; /* Set your image width */
 height:300px; /* Set your image height */
 }
 #gallery1 img{
position:absolute;
z-index:8;  

 }
   #gallery1 img.active{
z-index:10;
  }
 #gallery1 img.last-active{
 z-index:9;
  }

html code:

slideshow1.js:

function slideSwitch() {
var $active = $('#gallery1 IMG.active');

if ( $active.length == 0 ) $active = $('#gallery1 IMG:last');

var $next =  $active.next().length ? $active.next()
    : $('#gallery1 IMG:first');

$active.addClass('last-active');

$next.css({opacity: 0.0})
    .addClass('active')
    .animate({opacity: 1.0}, 1000, function() {
        $active.removeClass('active last-active');
    });
 }

 $(function() {
 setInterval( "slideSwitch()", 5000 );
 });

I read that I need to change $ to something else, like 'jQuery'. I tried that, but with no luck too. Can anyone help me?

share|improve this question
    
check source code and see if something is not working. –  amit Aug 2 '12 at 7:48
    
fire up firebug console or chrome's dev tools and check for errors. –  peteroak Aug 2 '12 at 8:49
    
Ok I used chrome's dev tools and it showed this error: "Uncaught TypeError: Property '$' of object [object Window] is not a function". So I suppose I should change $ to something else? Can anyone tell me the right way to change it?.. –  Andrius Aug 2 '12 at 10:25
    
I managed to fix that error, using (function ($){ code.. }); But slideshow still doesn't work.. –  Andrius Aug 2 '12 at 11:52
    
If wrapping your code in no-conflict wrappers (see Amit's answer below) doesn't fix the problem, then the issue appears to be a jQuery syntax issue, not a WordPress issue. –  Chip Bennett Aug 2 '12 at 14:42
add comment

closed as off topic by Chip Bennett, Chris_O, Wyck, Brian Fegter, kaiser Sep 3 '12 at 22:34

Questions on WordPress Development Stack Exchange are expected to relate to WordPress within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

Wrap the code like this to make it not conflict with other JS libraries wordpress loads.

jQuery(document).ready(function($) {
    // code
});

OR

(function($) {
    // code
})(jQuery);
share|improve this answer
add comment
up vote 0 down vote accepted

Used this approach and it worked:

var $j = jQuery.noConflict();

// code

$j(function() {

//code });

share|improve this answer
add comment

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