Changing Titles for Collections

Hi :wave: I’m new around here.

I’m moving from Webflow over to Ghost and [re]building my old site as a template for Ghost. I’m 98.46% there but have several things I can’t figure out.

We’ll keep this post to one of those issues:

I have an issue with what is output for the <title> tag on my site.

{{mata_title}} works great and gives me kinda what I need.

However when it comes to the Collections page(s) I get [site title] (page 1)

What I’d like is to universally have the following:

Posts/Pages/Tags etc: [title] – [site title]
Collections/Blog etc: [title] Page 1– [site title]

I’ve tried all first of filtering with {{#is}}, {{#if}}{{else}} etc, but nothing I do seems to be working. Maybe it can’t be done?

I would show you the site, but it’s running locally right now, to make sure it’s all working before I Ghost (Pro) it.

But here’s a short video of what I’ve built so far: https://cln.sh/MVNKLN

Any help would be awesome! :nerd_face::+1:

Hi, Kia! Welcome.

I think it’s possible to do what you want, but I honestly don’t think it’s worth it because it introduces unnecessary complexity. {{meta_title}} is always going to work and is customizable (using metadata), and I don’t think users are going to care about what the tab title says beyond it being useful.

That being said, here’s the code you’d use to get where you want. I’d test this on several pages to ensure it’s behaving as expected.

<title>{{#post}}{{title}} – {{@site.title}}{{/post~}} 
{{~#tag}}{{name}} Page {{../pagination.page}} – {{@site.title}}{{/tag~}}
{{~#author}}{{name}} Page {{../pagination.page}} – {{@site.title}}{{/author~}}
{{~^is "post,page,tag,author"}}{{@site.title}} Page {{pagination.page}} – {{@site.title}}{{/is~}}</title>

(The tilde ~ removes whitespace from the expression.)

1 Like

Hey Ryan, and thanks for the warm welcome :pray:

That code is pretty much perfect. Had to change a few things to make it fit what I need, but was great in pointing me in the right direction!

Here’s what I now have.

{{~#is "index,home"~}}
	{{@site.title}}
{{~else~}}
	{{~#post}}{{title}} – {{@site.title}}{{/post~}} 
	{{~#tag}}# {{name}} [Page {{../pagination.page}}] – {{@site.title}}{{/tag~}}
	{{~#author}}{{name}} [Page {{../pagination.page}}] – {{@site.title}}{{/author~}}
	{{~#is "paged"}}Collection{{else}}
		{{~^is "post,page,tag,author"}}{{@site.title}} [Page {{pagination.page}}] – {{@site.title}}{{/is~}}
	{{/is~}}
{{/is~}}

One thing that isn’t working is the Collections. So I’m not sure if I’m swimming against the tide, (It will never work), or if there’s something I’m overlooking.

Looking at this page…
https://ghost.org/docs/themes/helpers/is/

…it looks like I/we need ‘paged’ to also count the first page too.

P.S. The ~ is a lifesaver!

I think it’s still possible to do what you want, but I think there’s some confusion over terminology — or I’m not exactly sure what you want to do.

What do you mean by Collections/Blog ?

Also, paged will applies to any paged content after the first page, so it applies to tag, author, and index. The code you have would then show the entry for tag and the paged entry (when on page 2).

1 Like

Hey Ryan, yes, I think I’m confusing things a little, so I’ll try to explain as best I can :grimacing:

The site has Pages and Posts, as usual. And I have a static Homepage. But I also have Collections I’ve created, a list…

Tools
Testimonials
Quotes
Blog (As this is now a Collection due to the static homepage)

The above list is what I have an issue with when it comes to the Title tag. I’m not able to say have the Tools title tag to say “Tools – [SiteName]” and so on.

What I’m getting is “[SiteName] Page 1 – [SiteName]”

Tags and Authors (I class these as a Collection but due to the code, the Title tags are working fine)

Hope that makes sense.

Here’s a video of what I mean: https://cln.sh/PYpenl

Cheers!

After Tweeting about this problem, I had Med Prodigy reach out. They brainstormed a little and came up with the solution!

Here’s the final code:

{{~#is "index,home"~}}Apple Consultant  Tech Minimalist – {{@site.title}}{{else~}}
	{{~#post}}{{title}} – {{@site.title}}{{else~}}
		{{~#page}}{{title}} ~ Page {{../pagination.page}} – {{@site.title}}{{/page~}} 
	{{/post~}}
	{{~#tag}}#{{name}} ~ Page {{../pagination.page}} – {{@site.title}}{{/tag~}}
	{{~#author}}Author: {{name}} ~ Page {{../pagination.page}} – {{@site.title}}{{/author~}}
{{/is~}}
{{~^is "post,page,tag,author"}}{{title}} Page {{pagination.page}} – {{@site.title}}{{/is~}}

I can’t thank them enough :nerd_face::+1:

1 Like