WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

 width:400px; /* Set your image width */
 height:300px; /* Set your image height */
 #gallery1 img{

   #gallery1 img.active{
 #gallery1 img.last-active{

html code:


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');


$next.css({opacity: 0.0})
    .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

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.

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

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

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


(function($) {
    // code
share|improve this answer
up vote 0 down vote accepted

Used this approach and it worked:

var $j = jQuery.noConflict();

// code

$j(function() {

//code });

share|improve this answer

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