Website Building » Squarespace » Where Do I Put JavaScript in Squarespace?

Where Do I Put JavaScript in Squarespace?

Last updated on October 1, 2022 @ 9:56 am

There are two ways to add JavaScript to your Squarespace site: through a Code Block, or by injecting it into the header of your site.

To add a Code Block:

  1. Log into your Squarespace account and navigate to the page or post where you want to add the Code Block.
  2. Click the “+” icon and select “Code” from the list of options.
  3. Paste your JavaScript code into the Code Block and click “Apply.”

To inject JavaScript into the header of your site:

PRO TIP: If you are adding JavaScript to your Squarespace site, be aware that there are potential risks associated with doing so. Adding JavaScript can potentially introduce security vulnerabilities to your site, and it can also adversely affect the performance of your site. Therefore, it is important to only add JavaScript to your Squarespace site if you are confident that you understand these risks and how to mitigate them.
  1. Log into your Squarespace account and navigate to “Settings” > “Advanced” > “Code Injection.”
  2. Paste your JavaScript code into the Header field and click “Save.”

Conclusion:

Injecting JavaScript into the header of your Squarespace site is the recommended way to add custom code. This is because it ensures that your code will be loaded before other elements on the page, which can help avoid potential conflicts.

Drew Clemente

Drew Clemente

Devops & Sysadmin engineer. I basically build infrastructure online.