Javascript error after WP 4.5 update

Many people have been experiencing the dreaded Javascript error after WP 4.5 update. Basically, jQuery appears to have stopped working after the update and features on their sites are no longer working.

I’ve had a few clients contact me regarding this, some for our plugins and others for sites I maintain. While the problem does not exist in any of our plugins, I thought I would share what I’ve learned and how I was able to fix the problem.

Javascript error after WP 4.5 update

If portions of your WordPress site have stopped working, like dynamic navigation, hide/show elements, galleries, etc. you may be experiencing this issue as well.

If you view the Javascript console window (F12 in Chrome) you may find an error similar to this:

‘Syntax error, unrecognized expression: a[href*=#]’ or

‘Syntax error, unrecognized expression: a[href*=#]:not([href=#])’

The error is caused by any jQuery code snippet that contains something similar to the following expression: ‘a[href*=#]’ or ‘a[href*=#]:not([href=#])’. This snippet would most likely either be injected into the page, or loaded as a javascript file, by a plugin or theme. You can search your page source (view source), or click on any of the javascript file links, and do a search for the text that appears after the colon in the JS error you found.

Syntax error, unrecognized expression: RESOLVED

What I had to do on client site was to actually search each and every javascript file to find the where the format error was located. Once I found the offending code, I modified it to include quotes around the attribute values.

In this case: ‘a[href*=#]‘ became: ‘a[href*=”#”]‘. Once all of the code changes were in place and uploaded to the site – VIOLA!! Everything was back to working the way it should be.

WP 4.5 and jQuery Syntax Error

The main issue has been caused by the bundled jQuery that comes with the WordPress core has been updated to version 1.12.2. This new jQuery version is much more strict on the syntax passed in. This means the problematic snippets need to have the ‘href’ attribute value wrapped in quotes to be valid and quiet down the jQuery police.

Here some mentions of the problem in the WordPress forums: https://wordpress.org/support/topic/wp-45-and-jquery-syntax-error

And here it is again on the jQuery GitHub Repository: https://github.com/jquery/jquery/issues/2885

Comments are closed.