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?
In the sidebar of every page and post there is option to inject code on only that page.
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?
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):
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:
if (document.querySelector('.home-template')) {
// Inject
}
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!
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.
{{#is "home"}}
... schema
{{/is}}
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.
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.