Code won't work in wp

So, I’ve gotten this code to work just find on its own page but when I put it into wordpress the images won’t show and thus there is no slide show.

I’ve reviewed and reviewed but see no errors. Toss me a bone here.

http://binghamdentalutah.com/2nd-home-test/

It looks like there are a couple of small things falling over, no biggie, should be easy to solve.

Firstly, I see you have the following scripts in the <head> section


<script type="text/javascript" src="http://binghamdentalutah.com/wp-content/themes/Bingham%20Dental%20Utah/js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="http://binghamdentalutah.com/wp-content/themes/Bingham%20Dental%20Utah/js/faq.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script src="http://binghamdentalutah.com/wp-content/themes/Bingham%20Dental%20Utah/js/slides.min.jquery.js"></script>

And near the bottom of the page (probably in your footer.php)


<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js?ver=3.4.2'></script>

It seems the first jQuery script (1.7.2) isn’t on the server, no matter, we’ll get rid of it anyway :slight_smile:

What happens next is that your faq.js gets executed, but it of course doesn’t run because jQuery isn’t yet defined.

Next up, jQuery is included again, which is fine, but if the first jQuery would have loaded then it would now be overwritten.

Now the slides.min would run, but because there is another reference to jQuery in the footer, the $ variable gets overwritten again, which means the slides plugin gets deleted inadvertently.

I would recommend that you place your faq and slides plugin script in the footer of the theme, remove the reference to jquery 1.7.2 from the header, and remove the reference to jQuery 1.4 from the footer.

I am assuming that the jQuery 1.5.1 in the header is the one that Wordpress injects into the header, let me know if this is an issue for you and I can show you how to prevent this from happening or how to change the version.

For some reason wp is injecting the jquery 1.7.2 which has been annoying me for awhile.

The faq script is removed too and is being inserted still. I just removed it from the server too because I don’t need it anymore.

I just put the <script src=“http://binghamdentalutah.com/wp-content/themes/Bingham%20Dental%20Utah/js/slides.min.jquery.js”></script> in the footer.

Also, I have no idea where this **** is coming from in the footer because its not in my footer or any of my templates <script type=‘text/javascript’ src=‘http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js?ver=3.4.2’></script>

Well, shoot its working now so thx. However, I don’t know where that last part of code is coming from. I have to fix the alignment of some things but its working.

It would be worth checking your theme functions.php file (Or the template theme’s functions.php if you’re using a template). Quite often theme authors will inject their own version of jQuery.

For example in a recent theme I worked on, I added the following to my functions.php


/**  
  * Add jQuery from the CDN rather than Wordpress' bundled version  
  */
if (!is_admin()) {    

    wp_deregister_script('jquery');    

    wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js', false, null);    

    wp_enqueue_script('jquery');

}

Just do a search for wp_register_script and/or wp_enqueue_script in your theme/template folder to see what turns up.

I suspect a script with the handle ‘jquery’ might be enqueued as well as one with another handle (like jquery1.4 or something like that). Ideally the theme would be amended so it only includes the one version of jQuery :slight_smile: