How to Add Custom Code with Code Injection: A Complete Guide

By Michael Thompson

December 12, 2024 at 04:10 PM

Custom Code Injection Guide

Add custom HTML and scripts to enhance your site's functionality through code injection. This feature is ideal for implementing live chat services, domain validation, and analytics tools.

Best Practices:

  • Use code injection for scripts and HTML only
  • Add CSS through the custom CSS editor instead
  • Place JavaScript between
    <script>
    tags
  • Disable scripts while editing if needed

Code Injection Locations:

Header

  • Injects code into the
    <head>
    tag
  • Applies to all site pages

Footer

  • Injects code before the
    </body>
    tag
  • Appears on all pages

Lock Page

  • Appears above password field
  • Used for password-protected pages

Order Pages Available tags for order pages:

  • {orderId}
  • {orderSubtotal}
  • {orderSubtotalCents}
  • {orderGrandTotal}
  • {orderGrandTotalCents}
  • {customerEmailAddress}

Migrate order confirmation code

Migrate order confirmation code

Cookie Banner Integration:

  1. Enable cookie banner in settings
  2. Select Accept/Reject banner type
  3. Add integration code
  4. Save changes

Page-Specific Injection:

  1. Hover over page in Pages panel
  2. Click settings icon
  3. Select Advanced
  4. Add custom code

Troubleshooting:

  • Disable scripts in preview mode if editing issues occur
  • Type
    /safe
    at URL end to force disable scripts
  • Test custom code in incognito window
  • Remove problematic code during troubleshooting

Important Notes:

  • Checkout pages don't support code injection
  • Ajax loading may affect CSS injection
  • Blog post injection appears differently based on template
  • Index landing pages don't display injected code

For advanced customization:

  • Consider premium/business plans
  • Consult Squarespace Experts
  • Visit the Squarespace Forum for community support

Related Articles

Previous Articles