I am trying to: add google analytics code using Toolset - Settings - Custom Code but when I save and test I get the following error:
Snippet "google-analytics" has been updated.
There was error when trying to re-run the snippet:syntax error, unexpected '<', expecting end of file in /home/kingslover/public_html/wp-content/toolset-customizations/google-analytics.php on line 9 A problem occurred when executing snippet "google-analytics". The result of include_once is: ""
The code I am adding is:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="lien caché"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-5054472-130');
</script>
I tried removing what I thought might be unnecessary white spaces but that didn't change anything.
I'd be grateful if anyone can tell me what might be wrong with the code. The site is a parent theme so I cannot add it to functions.php like I would normally do, as it would get wiped out by any updates.
I cloned this site using Duplicator Pro from my test domain at whurld.com. The Toolset plugins say they are registered but they are not showing in the site list inside my Toolset admin page so is it not working because of something to do with needing the Toolset plugins to be properly associated with this domain (kingslover.com).
Many thanks,
Barry.
Hi, the snippet you're trying to add is HTML and JavaScript code, which is executed in the browser. Toolset's custom code snippet feature is for PHP code, which is executed on the server, so HTML and JavaScript aren't supported directly like this. It looks like you're using the Astra theme with Astra Pro, so you should be able to follow their recommendations here for adding a custom JavaScript snippet: https://wpastra.com/docs/add-custom-javascript-code-astra/
I would give that a shot first. Otherwise, you'll need to enqueue it in a child theme, or find another 3rd-party solution for enqueueing custom HTML and JavaScript.
Hi Christian,
Thank you for a super quick response. That was almost instant!!!
Many thanks,
Barry.