How can I change the title format?

(Lowell Heddings) #1

I’d like to change the title format for my forum. Right now it’s %title% %category% %sitename% which is fine for the vast majority of people, I’m sure.

Since I’m syncing articles over from my WordPress instance, the title format for the discussion topic ends up being almost exactly the same as the actual article. Which causes some weird issues in Google.

So I’d like to change the <title> format to something different than what displays on the actual page. Preferably:

Discussion: %title%

I found a place in one of the files where it appears I could make the change, but I’d rather not go making code changes to the actual source code. And even if I did I’m not sure how to apply those changes.

(Jeff Atwood) #2

Can you elaborate on the issues in Google?

(Lowell Heddings) #3

Having two pages with the exact same title isn’t great for Google strategy. Sometimes the two pages will show up one after the other in a search, and I would always want people to go to the article page rather than the discussion.

I figured out how to hack it using the crawler template, not sure how to override that in a plugin though.

(Kane York) #4

I see these two titles:

<title>How to Disable Your Webcam (and Why You Should)</title>

<title>How to Disable Your Webcam (and Why You Should) - How-To Geek Discussion</title>

Is the “Discussion” at the end not good enough?

(Lowell Heddings) #5

No, because Google cuts off after the first x number of characters anyway. So nobody looking at a Google result will ever see the stuff at the end.

I’m not even sure what is going on with this result… but you can see that the title format is exactly identical. Maybe because Google bots are actually executing the Javascript and reading the title element or something. Unsure.

So I’d much prefer to have the indexed topic title start with "Discussion: " instead. I’m guessing that anybody who uses Discourse to replace their WordPress comments would probably want to do the same thing (once they notice at least).

(Robin Ward) #6

It looks like the order of the crawlable title comes from application.html.erb:

<%= content_for?(:title) ? yield(:title) + ' - ' + SiteSetting.title : SiteSetting.title %>

We could add a site setting to add the title first - I think the JS version of the app would not be the same though unless that was updated too, but I assume it’s only important for crawlers anyway?

(Lowell Heddings) #7

Hmm. That would work, but then my forum titles would start with “How-To Geek Discussion” which is a long string to add to the beginning of every page - would make all of the other topics sorta useless in Google search since you would barely see any of the title. And if I changed it to just “Discussion” that might be confusing for people on the home page.

Maybe something like a site setting field that accepted wildcards for the title tag format. Like you do for this:

That way I could add “Discussion: %{topic_title}” as my preferred format, but other people could do it a different way if they wanted to.

(Jeff Atwood) #8

You kinda scared me when you said “wildcards” those are just substitutions :wink: