Squarespace Code Injection Explained (2026): Where It Is, What It Does and How to Use It Safely

Back to discover
Squarespace Help Center guide to code injection, showing header, footer, page and Lock page options

Disclosure: some links in this article are affiliate links. If you buy through them, SquareLocator may earn a commission at no extra cost to you. I only recommend tools I would use on client sites.

Squarespace code injection powers most of the customisations you see on Squarespace sites: analytics tags, verification codes, chat widgets and plugin scripts. It is also the feature most likely to break a site when used carelessly. I have run Altitude Design, a UK Squarespace agency and Platinum Partner, since 2018, and code injection is something I open on almost every build.

Quick answer: code injection lets you add your own HTML and JavaScript to the <head> or the end of the <body> of every page on your Squarespace site, or to the head of a single page. On version 7.1 you find the site-wide panel by opening the Pages panel and clicking Custom Code, then Code Injection. Per-page code goes in the page's settings under Advanced, in Page Header Code Injection. It is available on the Core, Plus and Advanced plans, not on Basic.

Elfsight

Ready-made widgets (reviews, Instagram feeds, chat, forms) that install with a short snippet in a Code Block or Code Injection.

Try Elfsight freeElfsight on SquareLocator

What is code injection in Squarespace?

You cannot edit your template's HTML directly on 7.1, so Squarespace gives you a set of text boxes whose contents are inserted into specific places in the page source. That is all code injection is.

According to the official Squarespace code injection guide, the boxes accept valid HTML and JavaScript. JavaScript must be wrapped in <script></script> tags. CSS works too if you wrap it in <style></style> tags, although Squarespace recommends the Custom CSS editor for styling. Squarespace's support team cannot help with custom code, so you are on your own once you start pasting things in.

Which Squarespace plans include code injection?

I checked Squarespace's pricing page today. Code injection is included on Core, Plus and Advanced, and listed as not included on Basic. The help article says the same, adding that some legacy billing plans also have it.

Plan Billed annually Billed monthly Code injection JavaScript in Code Blocks
Basic $19/mo $25/mo No No
Core $29/mo $39/mo Yes Yes
Plus $49/mo $65/mo Yes Yes
Advanced $99/mo $139/mo Yes Yes

Basic also carries a 2% transaction fee on online store sales, which Core and above do not. Basic still includes the Custom CSS editor and a basic Code Block for HTML and CSS; what you lose is scripts. If you downgrade to Basic, Squarespace's premium features article says your code stays in the Code Injection panel for reference but stops affecting the site. For the full breakdown, see my Squarespace pricing explained guide.

Where to find code injection

Site-wide code injection on 7.1

Open the Pages panel and click Custom Code at the bottom, then Code Injection. Menu labels do move occasionally; the help article above links straight to the panel. You need a computer, as the Squarespace app does not offer code injection.

Site-wide code injection on 7.0

On 7.0 sites, open the Pages panel and click Website Tools, then Code Injection. The boxes behave the same way, apart from an Ajax quirk covered below. Still on 7.0? Read is Squarespace 7.1 going away.

Page header code injection

To add code to one page only, hover over the page in the Pages panel, click the gear icon and open the Advanced tab. Whatever you paste into Page Header Code Injection goes into the <head> of that page alone. Squarespace warns against putting visible HTML here, because it can disappear when header transparency is turned off. Use it for <style>, <script> and structured data.

Blog pages also have Post Blog Item Code Injection, which adds code to every post on that blog.

Lock page, order confirmation and order status

The site-wide panel has extra boxes. Lock Page code appears above the password field on a password-protected site or page, and cannot be added during a trial. Order Confirmation and order status code appears after a purchase and is where conversion tracking usually lives. Squarespace provides tags such as {orderId} and {customerEmailAddress} you can pass into tracking scripts.

Code injection does not run on index landing pages, and checkout pages do not support custom code at all.

Header vs footer: which box should you use?

The Header box injects into the <head> of every page. The Footer box injects just before the closing </body> tag. My rule of thumb:

  • Header: anything a third party tells you must be in the head. Verification meta tags, Google Tag Manager's main snippet, font loading, global styles and scripts that other code depends on.
  • Footer: scripts that work on the page content, such as tweaks that find and change elements, chat bubbles and most floating widgets.

Common legitimate uses (with snippets)

Google Tag Manager

Google Tag Manager lets you manage analytics and ad tags from one container. The main snippet goes in the Header box. Replace GTM-XXXXXXX with your own container ID from Google Tag Manager:

<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-XXXXXXX');</script>
<!-- End Google Tag Manager -->

Google's second, <noscript> part is meant for straight after the opening body tag. Squarespace has no box there, so put it in the Footer box or leave it out.

Caveat: if you use Squarespace's built-in Google Analytics connection, Squarespace says not to add Analytics code here as well. Meta Pixel also has a built-in integration, and Squarespace says to remove injected pixel code before using it.

Verification tags and font loading

Verification services usually give you a single <meta> tag for the Header box. Font services such as Adobe Fonts give you a <link> or <script> embed for the header too, with the font applied through Custom CSS.

A per-page style tag

To hide the footer on one landing page, paste this into that page's Page Header Code Injection:

<style>
  /* Hide the site footer on this page only */
  #footer-sections {
    display: none;
  }
</style>

Confirm the selector with your browser's inspector first, as Squarespace updates can change IDs and class names.

A simple footer script

This Footer box script opens links to other websites in a new tab:

<script>
document.addEventListener('DOMContentLoaded', function () {
  document.querySelectorAll('a[href^="http"]').forEach(function (link) {
    if (link.hostname !== window.location.hostname) {
      link.setAttribute('target', '_blank');
      link.setAttribute('rel', 'noopener');
    }
  });
});
</script>

Order confirmation tracking

To stop a conversion script firing again every time a customer refreshes the order page, Squarespace recommends wrapping it in its first page view tags:

{.if firstPageView}
<script>
  // Paste your provider's conversion script here
</script>
{.end}

Plugin and widget scripts

Elfsight widgets come with a two-line install code: a loader script and a placeholder element. Elfsight's own help centre suggests putting the loader line in the Header box if a widget only appears after a refresh:

<script src="https://elfsightcdn.com/platform.js" async></script>

The second line, the widget's <div>, stays in a Code Block where you want the widget to appear. Floating widgets such as an AI Chatbot or Cookie Consent banner can go in the Footer box to show on every page. Inline ones like the Instagram Feed or Google Reviews go in a Code Block. See my Elfsight review and the guides to adding an Instagram feed, adding a cookie banner and adding an AI chatbot.

Paid plugins from Will Myers and SQS Mods, such as Will Myers' Mega Menu for Squarespace 7.1, typically ask you to paste supplied code into Code Injection, a Code Block or Page Header Code Injection. Follow each plugin's instructions exactly.

Structured data (schema)

You can add JSON-LD structured data, for example a FAQ or LocalBusiness block, to a single page through Page Header Code Injection inside a <script type="application/ld+json"> tag. Test it with Google's Rich Results Test, as one missing comma invalidates the block.

Code injection vs Code Block vs Custom CSS

Here is how I decide between them:

  • Custom CSS is for styling only: colours, spacing, fonts, hiding elements. It is available on every plan. If your change is purely visual, start with my guide to custom CSS in Squarespace.
  • A Code Block puts HTML (and on Core and above, JavaScript and iframes) at a specific spot on a page. Use it for embeds that need to appear in the layout, such as an inline widget, a form or a map. If you write a lot of code in blocks, Code Block Editor by SQS Mods adds a proper editor; see my Code Block Editor review.
  • Code injection is for code that is invisible or global: tracking, verification, loaders, scripts that change elements across the site, and per-page head code.

Using code injection safely

  • Only paste code from sources you trust. Injected JavaScript runs in every visitor's browser with full access to the page, including forms.
  • Keep a copy. Before editing, copy the existing contents of each box into a text file with the date. If something goes wrong, a dated backup makes undoing the mistake a two-minute job.
  • Label everything. Add an HTML comment above each snippet saying what it is and when it was added.
  • Test on desktop and mobile. Squarespace specifically warns that custom code can break appearance or behaviour, especially on mobile.
  • Watch performance. Every script is another download. Remove tags for tools you no longer use. The Health Scan tool from SQS Mods can help you audit a site; read my Health Scan review first.
  • Respect consent. If you run a cookie banner, Squarespace notes you can adjust third-party integrations based on visitor consent.

If injected code breaks the editor

When code interferes with the editor, Squarespace shows a message saying it detected an error loading your site preview and offers Disable Scripts in Preview. That only affects your editing view, not visitors. You can also force safe mode by adding /safe straight after /config in your editing URL. If neither works, remove code from each box one at a time until the problem stops.

Troubleshooting code injection

  • Code not showing in the editor preview. Scripts may be disabled in preview, and some code only runs on the live site. Check in a private or incognito window, as Squarespace recommends.
  • Works for you, not for a client (or the other way round). Ad blockers and privacy extensions block many analytics and pixel scripts. Test with extensions switched off before you assume the code is broken.
  • Nothing happens at all. Check your plan. On Basic, or after a downgrade, injected code is saved but inactive.
  • Script errors about something being undefined. Script order matters. A script that depends on a library has to load after it. Put the dependency in the Header box and the dependent script in the Footer, or keep both in one box in the right order.
  • Widgets only appear after a refresh (7.0). Ajax loading on some 7.0 templates can stop scripts and injected CSS running. Moving loaders into the header, as Elfsight advises, often fixes it; for CSS, use the Custom CSS editor.

When a plugin or no-code tool is a better choice

If you are copying a long script you do not understand to build something like a mega menu, a maintained plugin is usually safer: the author fixes it when Squarespace changes, and you get support. The best Squarespace plugins in 2026 and best free Squarespace plugins roundups are good starting points.

For connections to other services, such as shipping, accounting or marketing platforms, check Squarespace Extensions before pasting code.

And if what you actually want is design control without writing CSS or JavaScript, SquareKicker gives you a visual editor for styling changes. My SquareKicker review covers the trade-offs honestly. If you would rather learn to write the code yourself, I have rounded up the best Squarespace courses in 2026.

SquareKicker

A visual design tool for Squarespace that lets you make styling changes without writing the code yourself.

Try SquareKickerSquareKicker on SquareLocator

FAQs

Which Squarespace plans include code injection?

Code injection is included on the Core, Plus and Advanced plans, plus some legacy billing plans. It is not included on the Basic plan.

Where is code injection in Squarespace 7.1?

Open the Pages panel, click Custom Code at the bottom, then Code Injection. For a single page, click the gear icon next to the page, open the Advanced tab and use Page Header Code Injection.

What is the difference between header and footer code injection?

Header code is added inside the head tag of every page, which suits verification tags, Google Tag Manager and loader scripts. Footer code is added just before the closing body tag, which suits scripts that work on page content and floating widgets.

Why is my injected code not showing in the Squarespace editor?

Scripts can be disabled in the editor preview, and some code only runs on the live site. Check the live site in a private or incognito window with ad blockers switched off, and confirm your site is on Core, Plus or Advanced.

Can I add CSS with code injection?

Yes. Wrap it in style tags and it will work, including per page through Page Header Code Injection. For site-wide styling, Squarespace recommends the Custom CSS editor instead, which is available on every plan.

What happens to my code injection if I downgrade to Basic?

Your code stays in the Code Injection panel for reference, but it stops affecting your site until you move back to Core, Plus or Advanced.

Disclosure: some links in this article are affiliate links. If you buy through them, SquareLocator may earn a commission at no extra cost to you. I only recommend tools I would use on client sites.

Join +for free

Early access to the good stuff

Plugin drops, template picks and creator codes. Free in your inbox.

  • New plugin drops
  • Template picks
  • Creator discount codes