1

I was working on some css on a local wordpress install with MAMP when all of the sudden my mobile (jquery) menu stopped working on my post page (single.php). I checked my css and markup, nothing blocking the click register... Opened my chrome console and "Uncaught ReferenceError: jQuery is not defined". I click over to my homepage (home.php) tab, menu works fine, then refresh... same thing, menu is now broke and getting "Uncaught ReferenceError: jQuery is not defined" in console. My JQuery code was working fine, no-conflict.

jQuery(document).ready(function($) {

function togglescroll () {
  $('body').on('touchstart', function(e){
    if ($('body').hasClass('noscroll')) {
      e.preventDefault();
    }
  });
}

so wtf. Nothing was changed other than css when this stopped working. Checked my headers in chrome tools, jquery script is loading on homepage but not post page... weird. so I went ahead and properly deregistered and enqueued in functions.php

    if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
   wp_deregister_script('jquery');
   wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
   wp_enqueue_script('jquery');
}

This fixed the problem. HOWEVER

Removing the jquery enqueue from functions.php once again results in the menu working on the homepage but not the post page. 2 questions.

-Why did 'JQuery' just suddenly become undefined even on the homepage that was loading jquery in the head?

-Why is wordpress loading JQuery in homepage head but not post page (both get header.php)

Anyone have an idea of what might be going on there?

7
  • Do you see the network request for it? Is the jquery script getting included AFTER the script? Commented Dec 4, 2015 at 22:37
  • Check to see if you weren't requesting an http resource during an https request. That would block the resource from loading. Commented Dec 4, 2015 at 22:38
  • Possibly because you are enqueuing it only if an admin page is loaded. Is there a reason for that? It is not going to load on non-admin pages with that if statement you got there. You should probably take the enqueue out of the if statement.
    – Korgrue
    Commented Dec 4, 2015 at 22:40
  • on the post page, wordpress isn't loading the script so there isn't a request for it. On the homepage it's localhost:8888/elevatormag/wp-includes/js/jquery/jquery.js. I'm trying to replicated 'Jquery' being undefined on the homepage again even with jquery loading.
    – Bryan
    Commented Dec 4, 2015 at 22:42
  • @DannyGibas you mean if is not admin? That code block fixes the problem, but i'm trying to understand what caused the seemingly random occurrence of is stopping working
    – Bryan
    Commented Dec 4, 2015 at 22:52

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.