> For the complete documentation index, see [llms.txt](https://docs.themeupstudio.com/travio/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.themeupstudio.com/travio/getting-started/code-injection.md).

# Code Injection

### Code Injection (Site Header)

Travio reads a few **global JavaScript variables** (Content API key + behavior flags) **before the theme scripts run**, so this snippet must go into **Ghost → Code Injection → Site Header** (the `<head>` area).

#### Step 1 — Open Code Injection in Ghost Admin

1. Log in to your Ghost Admin.
2. Go to **Settings → Advanced → Code Injection**.

<div data-with-frame="true"><figure><img src="/files/qAhwR8ttPWVX4rfRhBEi" alt=""><figcaption><p>Code injection module in Ghost Admin Setting</p></figcaption></figure></div>

#### Step 2 — Paste the snippet into “Site Header”

1. Find the **Site Header** box (not Site Footer). Paste your snippet exactly as-is into **Site Header**.
2. Replace the example values with your own (details below).
3. Click **Save**.

{% hint style="danger" %}
Ensure you are adding the script in **Site header**&#x20;
{% endhint %}

<div data-with-frame="true"><figure><img src="/files/KIXQmhzfoEq5nAdVioUW" alt=""><figcaption><p>Paste the script in Site header and click Save</p></figcaption></figure></div>

Here’s a **copy/paste-ready** version with placeholders:

{% code title="Code injection in Site header of your Ghost website. Copy and Paste this script as is then update the variable values as per your preferances." lineNumbers="true" %}

```html
<style>
  :root {
    --travio-logo-nav-height: 22px; /* header logo size */
    --travio-logo-cta-height: 22px; /* CTA logo size */
  }
</style>

<script>
  window.TRAVIO_CONFIG = {
    contentApiKey: "abc123def456efg789skjbfkjsb7kbc",
    openLinksInNewTab: true,
    footer: {
      socialIcons: {
        google: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-brand-google"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M20.945 11a9 9 0 1 1 -3.284 -5.997l-2.655 2.392a5.5 5.5 0 1 0 2.119 6.605h-4.125v-3h7.945" /></svg>',
        behance: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-brand-behance"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 18v-12h4.5a3 3 0 0 1 0 6a3 3 0 0 1 0 6h-4.5" /><path d="M3 12l4.5 0" /><path d="M14 13h7a3.5 3.5 0 0 0 -7 0v2a3.5 3.5 0 0 0 6.64 1" /><path d="M16 6l3 0" /></svg>',
        dribbble: '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-brand-dribbble"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0" /><path d="M9 3.6c5 6 7 10.5 7.5 16.2" /><path d="M6.4 19c3.5 -3.5 6 -6.5 14.5 -6.4" /><path d="M3.1 10.75c5 0 9.814 -.38 15.314 -5" /></svg>'
      }
    },
    filters: {
      visibility: {
        articles: {
          destination: true,
          experiences: true
        },
        videos: {
          destination: true,
          experiences: true
        },
        archive: {
          destination: true,
          experiences: true,
          date: true
        },
        author: {
          destination: true,
          experiences: true
        },
        tag: {
          destination: true,
          experiences: true
        },
        tagDestination: {
          destination: false,
          experiences: true
        },
        tagExperience: {
          destination: true,
          experiences: false
        }
      }
    }
  };
</script>
```

{% endcode %}

**Why Site Header (not Footer)?**

Ghost places Site Header code inside `<head>`, while Site Footer code is injected before `</body>`. For Travio, the goal is to define `window.TRAVIO_CONFIG` **before** the theme JS reads it.

#### Step 3 — Create a Custom Integration (to get the Content API key)

Ghost’s official docs recommend generating your **Content API URL + key** by creating a **Custom Integration**.

1. In Ghost Admin, go to **Settings → Integrations**.
2. Click **Add custom integration**.
3. Name it something like: Travio Theme.
4. Click **Add.**
5. After creation, a popup will appear. Copy these from the popup:
   * **Content API Key** → to be pasted into `contentApiKey`&#x20;
6. Click **Save** in the Custom integration popup.
7. Open Code Injection module ([explained earlier](#step-1-open-code-injection-in-ghost-admin)).
8. Paste the Content API key value for the variable `contentApiKey`\
   `window.TRAVIO_CONFIG = {`\
   `contentApiKey: "123dsfd456sffeg9w87gdv4sg432s1v",` \
   `...`\
   `}`
9. Click **Save** button.

{% hint style="success" %}
**Content API** keys are **safe to use in the browser** because they only allow **read-only access to public content**.
{% endhint %}

{% hint style="warning" %}
Your **Admin API key** is different and must never be placed in client-side code. (Travio doesn’t need Admin API for normal use.)
{% endhint %}

Below are the step-by-step snapshots for adding the Content API key (and API URL) in Code injection, so Travio can use it.

<div data-with-frame="true"><figure><img src="/files/Cdjy8hIRvr8wLWrgzH5c" alt=""><figcaption><p>Navigate to Integrations module in Ghost Admin Setting and Click Add custom integration</p></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/Q3LPlrpfTnqI4e6yfga8" alt=""><figcaption><p>Add the integration's name and click Add</p></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/ah3PStl4eEukjRL1X4Pb" alt=""><figcaption><p>Copy the Content API key (API URL is optional) and click Save</p></figcaption></figure></div>

<div data-with-frame="true"><figure><img src="/files/mIVtQgOdRRimYPfrpN6e" alt=""><figcaption><p>Paste the copied Content API Key in the Code injection script and click Save</p></figcaption></figure></div>

In the next section, we will look at the variables defined in Code injection and their purpose.
