Link to home
Start Free TrialLog in
Avatar of andieje
andieje

asked on

How to include jquery and jquery ui (slider) properly in wordpress

Hi

I have a page in wordpress which i can get to work by doing the following and adding this directly to the page
  <!-- Load jQuery and jQuery UI -->
  <script src="//code.jquery.com/jquery-1.9.1.js"></script>
  <script src="//code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
        
  <!-- Load the jQuery UI CSS -->
  <link rel="stylesheet" href="//code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />

<script>
  <!-- jQuery UI Slider code -->
  $(function() { etc

Open in new window


Ive tried adding the jquery properly in the functions file but it doesnt work

function my_scripts_method() {	
   		wp_deregister_script('jquery');
   		wp_register_script('jquery', "//code.jquery.com/jquery-1.9.1.js", false, null);
   		wp_enqueue_script('jquery');

		wp_deregister_script('jquery-ui');
		wp_register_script('jquery-ui', '//code.jquery.com/ui/1.10.3/jquery-ui.js', false, null);
		wp_enqueue_script('jquery-ui');
	}

Open in new window





add_action( 'wp_enqueue_scripts', 'my_scripts_method' );

But this doesnt work and I cant get a slider to dispay on my page as I can when include the files directly

thanks
Avatar of Jason C. Levine
Jason C. Levine
Flag of United States of America image

WordPress includes JQuery and JQueryUI by default...it's part of the core load-in.

I'm thinking that by attempting to do the above you are a) breaking something and/or b) your slider is bombing out for a different reason.
ASKER CERTIFIED SOLUTION
Avatar of andieje
andieje

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Nope, it should have just worked.  I wonder if the theme you are using unenqueued JQuery or some other weird thing?

Anyway, using enqueue is the correct way to go, so you figured it out.
Avatar of andieje
andieje

ASKER

I figured out the solution myself and posted the approach used