Report malware

By Michael Thompson

December 12, 2024 at 04:10 PM

Code injection enables you to enhance your site by adding custom HTML and scripts for features like live chat services, domain verification, and analytics.

Important Notes Before Using Code Injection:

  • Scripts may need to be disabled while editing
  • JavaScript must be wrapped in
    <script>
    tags
  • CSS should preferably go in the Custom CSS Editor
  • Ajax loading might prevent CSS from loading properly
  • Checkout pages don't support injected code

Adding Code to Different Sections:

Header

  • Inserts code into the
    <head>
    tags of all pages
  • Best for site-wide scripts and integrations

Footer

  • Adds code before the closing
    </body>
    tag
  • Useful for analytics and tracking codes

Lock Page

  • Appears above password field on protected pages
  • Recommended to use Lock Screen panel instead

Order Pages Available tags for order-related pages:

  • {orderId}
    : Order number
  • {orderSubtotal}
    : Order subtotal
  • {orderGrandTotal}
    : Total order amount
  • {customerEmailAddress}
    : Customer's email

Page-Specific Injection:

  1. Hover over page in Pages panel
  2. Click settings icon
  3. Add code in "Code Injection to Page Header"
  4. For blogs, use "Code Injection for Blog Post Items"

Cookie Banner Integration:

  1. Enable Cookie Banner in settings
  2. Choose "Opt-in and Opt-out" type
  3. Add conditional code for third-party integrations
  4. Save changes

Warning mark in a red circle

Warning mark in a red circle

Troubleshooting:

  • Use "/safe" at URL end to disable scripts
  • Test in incognito mode to view custom code
  • Remove problematic code temporarily while troubleshooting
  • Consider consulting a Squarespace Expert for complex customizations

Remember to always backup your code before making changes and test thoroughly in preview mode before publishing.

Related Articles

Previous Articles