I have a Wordpress site (v4.2) and Civi 4.6.4 (although about to update). Every page on the public facing site generates a JS error (SyntaxError: Unexpected token '<') referring to wp-login.php redirecting to the l10n-js file. I'm getting nowhere trying to understand a) why a public facing page is referencing wp-login.php in any event, let alone why a JS error is then getting generated.

On contribution pages where the name and address profile uses the AJAX lookup for state/province, this is failing, leading to users not being able to successfully make a transaction. Not sure if the above JS error is the root cause of this, but two additional JS errors are appearing on these pages when trying to complete the profile:

CRM.url called before initialization - referring to Common.js (line 1371) and then TypeError: undefined is not an object (evaluating 'tplURL[mode]') - referring to crm.ajax.js line 26

Any insights most welcome.

  • The initial error seems to be caused because pages are attempting to load a script using src="/wp-admin/admin.php?page=CiviCRM&q=civicrm/ajax/l10n-js/en_GB&r=NSPzH. This is going to work fine if the user is logged in, but as an anonymous user this presumably triggers the attempt to load wp-login.php, hence the script is seeing the opening '<' and the error gets generated. Changing the theme used stops the problem, so I'm looking at the theme as a next step. – Graham Aug 31 '15 at 20:58
  • Does your theme contain a login page (one of it's own as) or something in page.php that's invoking wp-admin, is it a configurable thing? – Lesley Evensen Aug 31 '15 at 23:17
  • @Graham - I'm going to post a more detailed answer on how to troubleshoot - not because you need it, but because I intend to close some questions as duplicates of this. – Jon G - Megaphone Tech Jul 18 '18 at 21:10

Finally located the source of the problem. Every page on the site included a widget in the footer using an HTML snippet for a CiviCRM sign-up form. The HTML snippet, despite being the one generated by the profile, was incorrect, and included a reference to an admin URL for a script, which wouldn't be accessible to non-logged in site visitors. Removing it resolved the issue.

  • 1
    Just to update further on this, the default HTML snippet for the profile includes the line "var CRM = {"config":{"isFrontend":false}};" which to my mind looks incorrect. I would guess that this needs to set to 'true' for any public facing snippet?. Also, at the end of a list of Javascript files I see the following: "<script type="text/javascript" src="/wp-admin/admin.php?page=CiviCRM&amp;q=civicrm/ajax/l10n-js/en_GB&amp;r=Lg7uq">" which makes me think that the snippet won't necessarily work for a non-logged in user, and looks to be the cause of my initial JS error noted in the question. – Graham Sep 1 '15 at 9:08

Generically: You have a Javascript error, so I would definitely consult the Troubleshoot Javascript errors post which describes additional steps to try.

That said - I know what your problem is, and would like to give a step-by-step of how I worked it out.

In your Javascript console (press F12 in your browser, then "Console" tab) you'll see a bunch of errors - but the first starts with "SyntaxError". A syntax error in JS will generally disable all the following JS on the page, which will lead to other JS not loading. So ignore everything after the SyntaxError, that will get fixed when you find the syntax error.

Assuming your error is:

SyntaxError: expected expression, got '<'[Learn More] en_US:1
...(more errors below)

I can see the problem is on line 1 of the en_US file.

So I open my browser's developer tools (F12). Then I go to the "Network" tab, filter by JS, and reload the page. I look for the en_US file. I right-click and select "Open in New Tab" (see screenshot below).

What you SHOULD see is a JavaScript file that tells CiviCRM how to load the correct translations for certain fields. What YOU will see is a first line with <[Learn More] on it.

The reason that's happening is you have some CMS plugin/module that's injecting data on to every page. You'll need to identify the plugin and change its settings.

enter image description here

Your Answer

