Using Code Injection

You can add custom code and scripts to your site using the Code Injection area in Website Settings.

Note: To use per-page code injection, upgrade your site to Squarespace 7. To learn more about the benefits of upgrading, visit Squarespace 5 vs. newer versions. When you're ready to switch, visit Moving from Squarespace 5 to Squarespace 7.

When to use Code Injection

Use Code Injection to add HTML and scripts that enhance specific parts of your site. These might include flash or JavaScript, a Google sitemapGoogle Translate, live chat services, domain verification for custom email services, or site analytics.

Code Injection isn't intended for adding content or styles. To add content to your site, visit Adding and editing content. To add custom CSS for styles, use the Custom CSS Editor.

Before you begin

  • Creating and adding code to Code Injection is an advanced modification that requires programming knowledge. Squarespace doesn't provide code-based support.
  • Code added to Code Injection fields will apply to all your site pages, regardless of any styles or style overrides you're using. Unlike Squarespace 7, Squarespace 5 doesn't support per-page code injection. If you need per-page code injection, visit Moving from Squarespace 5 to Squarespace 7.
  • For best results, keep the total amount of code in your Code Injection areas under 32,000 characters. If you go over this limit, it may trigger a Whoops error.
  • You can add code within the <head> tag using the Extra Header Code field for every Squarespace 5 site. You must be on the Unlimited plan to access all ten code injection points (as shown in the screenshot below).

 

Step 1 - Open Code Injection

  1. Log into your site and open the Website Management bar.
  2. Cick Website Settings under Structure.
  3. Go to the Code Injection tab.

Step 2 - Add HTML code

Select an Injection Region from the drop-down.

Note: If you're not on the Unlimited plan, you can only access the Extra Header Code injection region.

Paste your code into the HTML Code field.

 

Step 3 - Save

Click Update Information.

Once you add code to an injection region's code field, the drop-down for that region will include an Edited flag. 

Error messages

The Code Injection panel has a built-in validation tool, which uses the XHTML 1.0 syntax. Since this is an older validation method, it may return errors for valid code, especially JavaScript. 

If you're seeing an error message and you've confirmed that your code is valid, try adding it to your site using one of our other options for custom code. Only Code Injection has this built-in validation tool.

For more modern and robust Code Injection options, including per-page injection, consider switching to our current platform, Squarespace 7. You can read about Squarespace 7's Code Injection options on our Squarespace 7 help site. When you're ready to switch, visit Moving from Squarespace 5 to Squarespace 7.0 or Moving from Squarespace 5 to Squarespace 7.1.

Note: Adding or modifying code on your site is an advanced modification. We highly recommend that you have coding knowledge to use Code Injection. While we can't offer more help on this topic, here are some resources to point you in the right direction:

Was this article helpful?
1 out of 1 found this helpful