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've included the javascript by

wp_enqueue_script('slider', plugins_url( 'slider.js', __FILE__ ) );

with just a simple

$(document).ready(function () {
    alert("alert");
});

It shows up in the browser but doesn't prompt me with "alert".

PS: Forgot to mention I've also included the jquery, but still not working.

wp_deregister_script('jquery');
wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
wp_enqueue_script('jquery');

In addition to the answers, I also had to tell wordpress that my script depends on jQuery

wp_enqueue_script( 'slider', plugins_url( 'slider.js', __FILE__ ),array('jquery') );
share|improve this question

2 Answers 2

up vote 0 down vote accepted

A few things:

  1. The version of jQuery that ships with WordPress is run in noConflict() mode. Meaning you have to use jQuery instead of $ when you make your first reference.
  2. Don't register your own version of jQuery when you're developing. You're locking yourself in to a single version that may or may not be compatible with WordPress' other requirements.
  3. You can use the browser console to test things. Open your page, then hit F12 to launch the console. Type jQuery into the console and see whether or not it returns the correct object.
share|improve this answer

WordPress loads jQuery in "No Conflict" mode. The $ alias does not work. Use jQuery.(document) or wrap your code like...

(function($) { 
  $(function() {
    // more code using $ as alias to jQuery
  });
})(jQuery);
share|improve this answer

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.