Notes.

Google Map Shortcode v Google Analytics for WordPress

Today’s quirky discovery: a Google Map that I’d made with the excellent Google Map Shortcode worked in the blog when I was logged in, but when didn’t work when I was logged out.

Investigation of the source code of the page showed that the plugin was trying to create a JSON object, but when logged out, a link had a double-quote:

“Note how everything goes wrong after the href”
1
"info":"<div style='...'><div style='...'><a class='title' href="http://clientswebsite.com/" style='...'>...",

As you can see from the syntax colouring, this breaks the JSON, leading to a syntax error, leading to the map not being created.

It should look like this:

“Note how everything is syntax coloured correctly!”
1
"info":"<div style='...'><div style='...'><a class='title' href='http://clientswebsite.com/' style='...'>...",

Oddly, the Google Maps Shortcode plugin settings page shows a perfectly valid use of single quotes:

Google Maps Shortcode settings page, showing the valid use of single quotes.

So, what’s breaking it? Some forum posts for other Google Maps plugins suggested it might be Google Analytics for Wordpress.

This would make sense: something disabled when a superuser is logged in, and which is rewriting links… which the plugin does, in order to get better data:

Google Analytics for WordPress setting that causes it to rewrite links

Sure enough, disabling that setting makes the problem go away.

So: if your Google Maps shortcode doesn’t work when logged out, suspect a Google Analytics plugin rewriting your links.