How to Fix jQuery breaking your site for WordPress 4.5.x

Fix jQuery Breaking Your WordPress Site, FixMyWP guide header image

Quick Guide on updating your outdated WordPress theme or plugin jQuery selectors

Back when WordPress 4.5 was first released, we received many support requests for broken themes and plugins.

All of them had two things in common:
a. They were running WordPress 4.5.x
b. They had a specific jQuery issue, which resulted in the following jQuery syntax error (unrecognized expression):

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

While it seems like an issue with the 4.5.x version of WordPress, it’s really not. This jQuery error has to do with a theme or plugin that is using an outdated href selector.
Since I’m still getting such support requests, I decided to post a how-to on updating your WP theme/plugin jQuery selectors to work with the jQuery version that ships with WordPress.

Site down or showing an error? White screen, critical error or database connection error: we find the cause and get your site back up for a flat $199. See site down fixes →

How to Detect the WordPress Plugin or Theme which uses the outdated jQuery selector

First of all, you must find the offending piece of code and the file it belongs to. To do this, I suggest using the Chrome DevTools or Firefox Developer Tools (Firebug, the old Firefox add-on, was discontinued and is now built into Firefox). Open the page that has the issue, press F12 (or right-click and choose Inspect) and open the Console tab. The jQuery error should look like the one below, and next to it you will see the file name and line number, which you can click to see the outdated code and the path of the file it belongs to:

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

Notice: If you’re having difficulties using the browser’s developer tools, take a look at Google’s guide to the Chrome DevTools Console. The file path tells you whether the code comes from a theme (/wp-content/themes/) or a plugin (/wp-content/plugins/).

How to Fix the outdated jQuery selector

Once you find the file and the line where the jQuery selector resides, replace this piece of code:

				
					$( 'a[href*=#]:not([href=#])' ).click( function() {
				
			

with this one:

				
					$( 'a[href*="#"]:not([href="#"])' ).click( function() {
				
			

What you’re doing here is adding double quote marks around the hash symbols (#). When finished, save the file, upload it to your site and clear your cache, then hard refresh your page with CTRL+F5 (Cmd+Shift+R on a Mac). If the file belongs to a theme or plugin from WordPress.org or a developer, check for an update first, because your edit will be overwritten the next time it updates. For more on finding this kind of problem, see our guide to debugging compatibility errors.

★★★★★
Many hours of my time and nothing worked; and I suspected I could just be making things worse. So I looked for outside help and found FixMyWP who had the combination of reasonable prices and positive comments on various websites.
Michael Hilton UK
michaelhilton.org.uk

Site down or showing an error?

White screen, “There has been a critical error on this website”, a database connection error or a site that won’t load. We find the cause and get it back up. Flat rate of $199.

See site down fixesNot sure? Answer 4 quick questions

In this article

Need a hand with your site?

Answer four quick questions and see your flat price before you pay. Most fixes are done the same day or within 24 business hours.

Related articles