Jump to content

Trying to add custom data via javascript to the head tag

Recommended Posts

Site URL: https://evergreenfineartsfestival.com

Hi my site has many pages that include the current year and some other data.  I'm trying to inject that data via the head tag by clicking into Settings->Advanced->Code Injection, then on the pages using a code block to access the data.

The code injection is:

<script type="text/javascript">
  var year = "2021";
  var lastYear = "2020";
  var nextYear = "2022";
  var event = "55th";
  var friday = "27";
  var saturday = "28";
  var sunday = "29";

function docWrite(variable) {
    document.write(variable);
}
</script>

And the content looks like this in a code block:

<h2 style="text-align:center;white-space:pre-wrap;"><strong><script>docWrite(year)</script> Juror</strong></h2>

This is working fine on the home page, but on all other pages the variables aren't populated when I load the page.  I have to click on refresh to make them appear.  When I look at the page source everything appears to be where it should be.

Any ideas or help would really be appreciated!

Link to comment
  • Replies 3
  • Views 587
  • Created
  • Last Reply

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.