Solved

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

Posted on 2014-04-20
4
790 Views
Last Modified: 2014-05-07
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
0
Comment
Question by:andieje
  • 2
  • 2
4 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40011561
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.
0
 

Accepted Solution

by:
andieje earned 0 total points
ID: 40015788
Hi Jason

For one :) I couldnt get any jquery or jquery ui to work in wordpress even though it is supposed to be loaded by default. I could get it to work by adding jquery and jqueryui scripts directly to the page code from googls cdn  and it was fine.

I also managed to load jquery and jqueryui through the enqueue_scripts function so i could remove the includes from the page and that all works fine now. I believe you are supposed to do it like this in the functions file so that plugins dont cause conflicts.

However even though i have a working solution i am now most curious why jquery didnt work for me 'by default' in wordpress. Is there a setting in the admin panel or something i dont know about?

thanks
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 40015818
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.
0
 

Author Closing Comment

by:andieje
ID: 40046630
I figured out the solution myself and posted the approach used
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question