How do you include post title and internal tag in <title>?

I’m trying to fix the SEO of a ghost site, where I’d like the title of the post and the meta title of either the internal tag or page to be included. Something like this:

<title>{{post.title}} | {{tag.meta_title}}</title>

Is this possible? Whatever I’ve tried it’s not working.
I’m trying to combine multiple WP sites into a single instance of Ghost, since they have content collections, and all tags, pages, posts etc have custom meta functionality which I could use to make every content collection look very unique. It’s an awesome solution, apart from the content collections not being able to have their own domain, but I guess that might be implemented later on.

The default behavior for the title tag is to output a title based on the current context. For example, on posts, you’ll get the post title and on index pages, the site title and page.

What you’re after is basically creating a custom version of this, which is possible via the block helper:

The basic pattern is to create a custom block on your default.hbs page and then use contentFor to send up the custom title from each context.

Custom collections are possible using dynamic routing, which might be what you’re after. I recommend checking out our tutorial site and these docs:

Thank you!
I shall take a look right away to see if it’s a good solution.
Like I mentioned, I do use content collections with dynamic routing and that’s an amazing feature that makes me wanna switch blogging platforms. I’ve always wanted to merge my blogs into one site, to make it easier, but nothing has worked that way I wanted to until now with Ghost and their meta settings. Thank you again for that tip!

Awesome. Creating a custom meta title can be tricky, so don’t hesitate to post again if you run into any questions/problems!

Hello again!
It was a great solution, but I wonder if it’s possible to do it more dynamically. This is my current solution:

{{#contentFor "internalTag"}}
        {{#has tag="#oneInternalTag"}}
            Content collection tag title in plain text
        {{else has tag="#someOtherInternalTag"}}
            Content collection tag title in plain text
        {{else has tag="#aThirdInternalTag"}}
            Content collection tag title in plain text

It would be nice if I could just do “if this post has either tag1, tag2, tag3 do this and get tag’s meta title” like this:

{{#has tag="#tagOne, #tagTwo, #tagThree"}}

Don’t know if you saw my latest reply, but I did get into an issue I’d like to have seen solved. Please check the whole thread :blush:. I’d love some help and explanation on how the has helper works.

Can share more about what’s your ultimate goal? It’ll help give you a better response.

Sure. I thought I already did, but if you want the whole story, I can tell you :blush: It might help anybody else who’s looking for a similar or same solution to their blog situation.

My ultimate goal is:

I have 3 WP blogs I’d like to merge into one site, and I’d like to try Ghost to do this.

Each blog will have their own content collection, tagged with an internal tag.
In the theme of the index.hsb file of my theme, I can change from showing the @site.title to meta_title and the @site.description to meta_description that I’ve set for each internal tag.

This works great, btw and I love that it’s included with ghost. With WP you have to struggle with major plugins to get the same results or pay dearly for self-hosting. does not offer it at all with the free plan either.

On the front page, home.hbs I want to have a landing page, showing a link to each content collection, and I’ve created a page for each content collection to do so. In my routes.yaml file I’ve set the data attribute to get data from those pages. This works, but creating links to an internal tag does not, so that’s why I’ve created pages for this to work.

At each content collection’s individual post, I’d like the <title> to look like this, so the browser tab displays both the post title and the internal tag/data page fetches it and it looks more like if it was a separate blog, rather than a post of a blog with multiple categories. This is what I want:
<title> post title | tag.meta_title</title>.

I’ve solved the title thing a little, with your tip on using the contentFor block. Now my <title>tag in default.hbs looks like this:
<title>{{meta_title}} {{#is "post"}} | {{block "internalTag"}}{{/is}}</title>

The issue I’m having now is that I’d like to have a more dynamic solution, like mentioned in previous post. I’ll share it again for clarity:

This is my current solution:

{{#contentFor "internalTag"}}
        {{#has tag="#tagOne"}}
            Content collection tag title in plain text
        {{else has tag="#tagTwo"}}
            Content collection tag title in plain text
        {{else has tag="#tagThree"}}
            Content collection tag title in plain text

I don’t really know how the {{#has}} helper works, because I have not found anything about it online, except for all the tutorials and docs on the ghost page. I’d like to have my contentFor block look like this instead:

{{#contentFor "internalTag"}}
{{#has tag="#tagOne, #tagTwo, #tagThree"}}

If I only write meta_title in this way, I get the site title instead and that’s not what I want. Am I supposed to just write {{name}} instead, to get the tag’s name/meta_title?

I hope this was really thourough, because I don’t know how to explain my goals in any other way.

Thank you for any help.

Thanks for the detailed reply.

I’d first try what you suggested: use {{}}.

Your dynamic approach should work. What you’re trying to do is complex, so another helpful tool I’d use is the {{log}}, which will output the data to your terminal to make debugging easier.

Here’s a tutorial on how to set it up:

Unfortunately it does not work. I’ve tried everything now. I don’t understand why it does not work.

Is there a solution for this? I’m still trying to solve this. It is still unsolved. Why doesn’t it work when you say it should? Have I missed something?

If I understand what you’re tying to do, here’s an approach:

{{#is "post"}} {{!-- check whether we're on a post}}
  {{#post}} {{!-- open the post context --}}
    {{#has tag="collection1,collection2,collection3"}} {{!-- check for presence of collection tag --}}
      {{!-- assuming here that the collection is the primary tag on the post. --}}
      <title>{{title}} | {{}}</title> {{!-- post title | tag name --}}
      {{!-- not in one of those three collections --}}
      <title>{{title}}</title> {{!-- use title because we're in the post context}}
{{else}} {{!-- cover the cases when you're not on a post page --}}

Thank you, I shall try that and get back to you if it works. I don’t however use Primary Tags, but I guess I will have to if it makes it work.

Also, another question, if I share a post to social media or my post shows up on Google, will it display like “My post | My content Collection” or will it just share the post name. If it will only share the post name, this is kind of pointless as well, because I’ll need both of those functionalities if I’m gonna use this.

Hello again. It worked, but the problem is that I don’t plan on using primary tags this way. Thank you for the help. I guess there is no solution for this, not the way I want to. I think however this should be a feature included in future versions of Ghost. I’ve seen in the forum that many want to display their posts like this, because of the better SEO aspects when doing so.

Glad it worked! It’s not necessary to use primary_tag for this, but it makes it easier. Otherwise, you could take the route you mentioned by hardcoding the tag you’re looking for using has.

Another more manual route would be to use the post sidebar to update the title for each post. There, you can specify exactly what you want the title to be for Google, FB, and Twitter SEO purposes. That being said, the impact of these changes for SEO purposes will likely be negligible.

We do have an #ideas channel where you can put in your vote/request for new features. Our team consistently looks to it when figuring out what to build next.

1 Like

Thank you.
Yes, I’ve already written a post about this in the #ideas channel. I’m pretty lazy by nature :joy: so anything I can do to automate stuff/make things easier is always good, especially if you learn something new in the process.

1 Like