Complete Guide to Code Injection: How to Add Custom HTML and Scripts to Your Website
Code injection lets you enhance your site by adding custom HTML and scripts to specific areas. Here's a comprehensive guide on how to use it effectively:
Code Injection Locations
- Header: Adds code to the tag on all pages
- Footer: Inserts code before the tag on all pages
- Page-specific: Adds code to individual pages
- Lock Screen: Displays code above password fields
- Order Confirmation/Status Pages: Shows transaction-specific information
Best Practices
- Wrap JavaScript in
- Use the CSS editor instead of code injection for styles
- Consider Ajax loading limitations with CSS code
- Note that payment pages don't support custom code
Squarespace migration notification
Adding Code
- Open Code Injection panel
- Insert valid HTML/scripts in appropriate fields
- Click Save
Cookie Banner Integration
- Enable cookie banner in Cookies and Visitor Data panel
- Select Accept/Reject banner type
- Add necessary integration code
- Save changes
Order Status Page Tags
- {orderId}: Order number
- {orderSubtotal}: Order subtotal
- {orderSubtotalCents}: Subtotal in cents
- {orderGrandTotal}: Final total
- {orderGrandTotalCents}: Final total in cents
- {customerEmailAddress}: Customer email
Troubleshooting
- Disable scripts in preview for safe editing
- Type /safe at end of URL to bring up disable message
- Use incognito/private window to view custom code
- Remove problematic code temporarily for troubleshooting
For complex customizations, consider consulting a Squarespace Expert or exploring premium plans for additional features.