Solved

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

Posted on 2014-04-20
4
801 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
This article discusses how to create an extensible mechanism for linked drop downs.
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

861 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