Solved

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

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

679 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