Solved

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

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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 …
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now