# Code injection on the home page

**URL:** <https://forum.ghost.org/t/code-injection-on-the-home-page/36446>\
**Category:** Using Ghost\
**Created:** [February 16, 2023, 11:45pm UTC](https://forum.ghost.org/t/code-injection-on-the-home-page/36446 "2023-02-16T23:45:08Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Unmarked4564](https://avatars.discourse-cdn.com/v4/letter/u/848f3c/32.png) [@Unmarked4564](https://forum.ghost.org/u/Unmarked4564)\
**Post date:** [February 16, 2023, 11:45pm UTC](https://forum.ghost.org/t/code-injection-on-the-home-page/36446/1 "2023-02-16T23:45:08Z")

</div>

I want to inject an faq schema into my home page, but the only way that I can seem to inject into it is a site-wide injection. Is there any way to overcome this?

---

<div class="post-metadata">

**Author:** ![markstos](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/markstos/32/18182_2.png) [@markstos](https://forum.ghost.org/u/markstos)\
**Post date:** [February 17, 2023, 1:21am UTC](https://forum.ghost.org/t/code-injection-on-the-home-page/36446/2 "2023-02-17T01:21:40Z")

</div>

In the sidebar of every page and post there is option to inject code on only that page.

---

<div class="post-metadata">

**Author:** ![Unmarked4564](https://avatars.discourse-cdn.com/v4/letter/u/848f3c/32.png) [@Unmarked4564](https://forum.ghost.org/u/Unmarked4564)\
**Post date:** [February 17, 2023, 9:19pm UTC](https://forum.ghost.org/t/code-injection-on-the-home-page/36446/3 "2023-02-17T21:19:52Z")

</div>

I did notice that and I use it on my other pages, but my home page specifically isn’t listed in the pages or posts sections. When I say the homepage I mean the directory root, `example.com/`. Is there somewhere I can look to inject only into this page?

---

<div class="post-metadata">

**Author:** ![RyanF](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/ryanf/32/17448_2.png) [@RyanF](https://forum.ghost.org/u/RyanF)\
**Post date:** [February 17, 2023, 9:32pm UTC](https://forum.ghost.org/t/code-injection-on-the-home-page/36446/4 "2023-02-17T21:32:50Z")

</div>

There are lots of ways to do this! These would go in your global/site-wide code injection.

This will check if you’re on the homepage (assuming your homepage is the root path):

```javascript
if (window.location.pathname === "/") {
// Inject
}

```

If you’re outputting the `home-template` class in your theme, then you can also check for the presence of this class:

```javascript
if (document.querySelector('.home-template')) {
    // Inject 
}
```

---

<div class="post-metadata">

**Author:** ![Unmarked4564](https://avatars.discourse-cdn.com/v4/letter/u/848f3c/32.png) [@Unmarked4564](https://forum.ghost.org/u/Unmarked4564)\
**Post date:** [February 17, 2023, 9:43pm UTC](https://forum.ghost.org/t/code-injection-on-the-home-page/36446/5 "2023-02-17T21:43:24Z")

</div>

I can see how this would work in most cases, but in this case I am injecting an FAQ Page Schema. From my understanding, this wouldn’t work for this use case. Its possible that I am not understanding this correctly but I am reading it as an `if` statement to evaluate in the browser before executing some js. Thanks for the help!

---

<div class="post-metadata">

**Author:** ![RyanF](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/ryanf/32/17448_2.png) [@RyanF](https://forum.ghost.org/u/RyanF)\
**Post date:** [February 17, 2023, 9:59pm UTC](https://forum.ghost.org/t/code-injection-on-the-home-page/36446/6 "2023-02-17T21:59:40Z")

</div>

Sorry, I didn’t pick up on that. Do you mean a schema like for bots? Then, you would need to put it in your template.

```plaintext
{{#is "home"}}
... schema
{{/is}}

```

---

<div class="post-metadata">

**Author:** ![Unmarked4564](https://avatars.discourse-cdn.com/v4/letter/u/848f3c/32.png) [@Unmarked4564](https://forum.ghost.org/u/Unmarked4564)\
**Post date:** [February 17, 2023, 10:00pm UTC](https://forum.ghost.org/t/code-injection-on-the-home-page/36446/7 "2023-02-17T22:00:48Z")

</div>

Alright, pretty new to ghost and I haven’t messed around with themes yet so I’ll just leave it for now. Thank you for the pointers.

---

<div class="post-metadata">

**Author:** ![RyanF](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/ryanf/32/17448_2.png) [@RyanF](https://forum.ghost.org/u/RyanF)\
**Post date:** [February 17, 2023, 10:02pm UTC](https://forum.ghost.org/t/code-injection-on-the-home-page/36446/8 "2023-02-17T22:02:55Z")

</div>

Here’s a link to the is helper for reference. You’d add it to the `head` tag of your `default.hbs` file. It’s a good first customization to try out.

> **[Ghost Handlebars Theme Helpers: is](https://ghost.org/docs/themes/helpers/is/)**
>
> The #is helper allows theme developers to check the context of the current route. Read more about custom Ghost themes! 👻
