Why did ‘JQuery’ suddenly become undefined? Local WordPress MAMP

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

Read More
    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?

Related posts