Html site title helper

Dear forum,

I have a question about html site titles in custom pages and did not find an answer in the forum yet.
I have set up a custom page “custom-services.hbs” and linked it to the respective site inside the ghost GUI. So far everything works.

Now I would like to be able to change the title of the website itself (in the casper theme it is just implemented with the helper “{{meta_title}}”). The result should be in the format "TITLE_OF_BLOG | TITLE_OF_POST. {{meta_title}} outputs everytime only the name of my blog (is this maybe a bug? The documentation says, this helper outputs the title of the page/post and I’m 99% sure this was the case with other sites I built in the past). I found the helper {{title}} in the documentation, but this doesn’t output anything.

So my main questions are:

  • which helper can i use to access the specific title of a page or post?
  • does this then also work for pages which have a “custom-xy.hbs” template they are based on?

I’m currently using v 3.0.2 of ghost as a docker image.

Thank you in advance and all the best,
Jonas

Hi Jonas :wave:. {{meta_title}} outputs the meta title added to the meta information in the post settings. Clicking the cog in the top right hand corner of a post edit view and then clicking “Meta Data” will show this field.

If you want to modify how the title is formed you can use a mixture of helpers, such as the @site helper. You can find more info on it in our docs:

To get the output you’re looking then maybe something like this would work?

{{#is "post"}}
  {{#post}}<title>{{@site.title}} | {{title}}</title>{{/post}}
{{else}}
  <title>{{@site.title}}</title>
{{/is}}

Note that I’m using the post {{title}} here which bypasses {{meta_title}}. I would recommend experimenting with the meta options in Ghost before making too many edits to the theme itself. Hope this helps!

Hi David,

great, that was the solution!

	{{#is "home"}}
		<title>{{@site.title}}</title>
	{{else}}
		{{#post}}
			<title>{{@site.title}} | {{title}}</title>
		{{/post}}
	{{/is}}

… worked now for me.

Best regards and thank you,
Jonas

2 Likes

Hi @jonaswoehl I also need something similar (meta titles with company branding) for my site and the solution proposed by @DavidDarnes seems to work but I have a few doubts that maybe you can kindly clarify for me?

  1. Where did you add that snipped of code to? I’m adding it to the tag of the default.hbs (see image) file so that it can show on ALL pages depending on context (e.g., "#is “post” or #is “tag”, #is “home”,… etc) because the title is slightly different for posts vs. tag pages vs. home page.

  2. My main concern with taking this approach is related to SEO. Adding the context-based meta title approach to the of the default.hbs file renders the correct metadata when I inspect the page with Chrome’s devTools (see image), but when I check the “Search Engine Result Preview” (see image) in Ghost the meta title is not the same as in the devtools (which is what I need for SEO). In your site, did Google search results show the metadata version coming from default.hbs or the versoin coming from the Ghost CMS search engine preview?

Thanks!

devtools ghost