Code Injection

Code Injection allows you to insert custom code into different parts 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.

To begin using Code Injection:

  1. Choose "Code Injection…" from the Site menu.
  2. Enter your code into the window.

There are four places code can be injected:

Before <html>

Inserted at the absolute beginning of the page, before the <html> tag. Please do not use any actual HTML code here. Note that the code inserted here will not appear in Sandvox while editing, only on the published site.

Example uses:

<head> area

Inserts code in between the <head> and </head> tags.

Example uses:

Within <body> tag

Inserts code inside of the <body> tag. This literally means within the tag itself, not between <body> and </body>.

Example uses:

Before </body>

Inserted right at the end of the main HTML code, just before the </body> tag. The main purpose is for Javascripts that process the preceding HTML code.

Example uses:

Insertion Level

Normally, you use Code Injection to affect every page in a site. However, you can also use Code Injection upon a single page or a subset of pages.

To use Code Injection at a selected level:

  1. Select the page in the Site Outline. (This can be a collection if you wish)
  2. Open the Site menu.
  3. Hold down the option key and choose "Code Injection at Selected Level…"

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.

Inheritance

Each tab of the Code Injection window contains a checkbox labeled "Include on contained pages." This is turned on by default.

Uncheck the box and the code will only be inserted for the page indicated in the Code Injection window's title, rather than all the pages below it in the Site Outline's hierarchy.

How can we improve this page? Let us know.