Code Injection

Code Injection allows you to insert custom code, such as <script> tags or additional HTML, into all or part of a Sandvox site. For example, you might use it to add PHP directives to your site. Code Injection is a Sandvox Pro feature only.

You can insert code once but have that code appear on every page of your site, or you can insert code on a selected page or pages, so that only the pages you have selected are affected.

Inserting code on every page

To insert code on every page of a site:

  1. From the Site menu, choose "Site Code Injection".
  2. Enter your code into the window.

Inserting code on selected pages

You can also apply Code Injection to a single page or a subset of pages.

To use Code Injection on a single page or group of pages:

  1. Select the page or pages to which you wish to apply code in the Site Outline.
  2. Open the Site menu.
  3. Choose "Page Code Injection…"

Any code entered will only affect the page you selected in the Site Outline (and any children it may have) rather than the entire site.

Where code can be injected

Code can be injected in several places; your options are grouped into three tabs on the Code Injection screen.

Before Document

Use this field to insert code at the very beginning of the document, before the opening <html> tag. Do not insert HTML or Javascript code here; this location is only for server-side scripts (such as PHP code) to affect the headers, set cookies, etc.

Head area

When you select the "Head area" tab, you will see two input fields. The first is for those circumstances when you want to insert code early in the header (after the first <meta> tag); the second is the one that you would ordinarily use, to insert code later in the header.

Document body

When you select the "Document body" tab, you will see three input fields.

Body (HTML tag)
Use this field to insert code directly (for example JavaScript 'onload') inside the <body> tag itself.
Body start
Use this field to insert code after the <body> tag. This is generally used by JavaScripts that prepare for the rest of the page contents.
Body end
Use this field to insert code at the end of the page, right before the </body> tag. This is generally used to include JavaScript that processes the preceding page contents.
How can we improve this page? Let us know.