Custom HTML and Script Insertion Guide - How to Add Code to Your Squarespace Site

By Michael Turner

December 12, 2024 at 04:09 PM

Code Insertion is a feature that allows you to enhance your site with custom HTML and scripts in specific locations. Here's everything you need to know about using it effectively:

Key Locations for Code Insertion:

  • Header: Adds code within tags on all pages
  • Footer: Places code before tag on all pages
  • Lock Page: Displays code above password field on lock screen
  • Order Confirmation Page: Shows on gift cards/memberships checkout completion
  • Order Status Page: Appears after physical products/digital downloads checkout

Important Guidelines:

  • Wrap JavaScript in
  • Use Custom CSS editor instead of code insertion for styling
  • Ajax loading may prevent CSS from loading properly
  • Checkout page doesn't support custom code

Integrating with Cookie Banner:

  1. Enable Cookie Banner in [Cookies and Visitor Data] panel
  2. Choose [Opt-In and Opt-Out] for visitor consent options
  3. Add required integration code
  4. Save changes

Warning mark in red circle

Warning mark in red circle

Available Order Page Tags:

  • {orderId} - Order number
  • {orderSubtotal} - Order subtotal
  • {orderSubtotalCents} - Subtotal in cents
  • {orderGrandTotal} - Total order amount
  • {orderGrandTotalCents} - Total in cents
  • {customerEmailAddress} - Customer's email

Page-Specific Code Insertion:

  1. Access page settings
  2. Open Advanced Settings
  3. Add code to Page Header or Blog Post Item sections

Safety Considerations:

  • Disable scripts in preview when troubleshooting
  • Test custom code in incognito/private window
  • Remove problematic code temporarily while debugging
  • Follow best practices for third-party customization

Remember to always backup your code before making changes and test thoroughly before publishing to ensure functionality.

Related Articles

Previous Articles