¿Especificar formato de etiqueta <title> personalizada por tipo de página?

Is it possible to customise the format for title tags on a page type basis? If not, does anyone know of a plugin, or a plugin that could be used as a basis to create this functionality please?

We can currently do it for email titles:

[%{site_name}] %{optional_pm}%{optional_cat}%{topic_title}

It would be great if we could do this for the view Topic and view Category pages too.

Anyone have any thoughts on this please?

It is not currently possible to modify the title format.

What’s the purpose of changing the title? If it is for the benefit of users browsing the site, then it should be possible to override the title using a theme component. If you want to change the title that Google sees, then you would need to use a plugin.

2 Me gusta

It’s mainly for the purpose of Google and other bots but it makes sense for readers too (I just need to add one word to make what the forum is about more explicit).

Do you know of any links to threads or guides that could help with making such a plugin please David?

If you just want to add a single word to the end, you could add it to the “Title” site setting. Although that will appear in more places than just the page title.

For crawlers, a plugin would need to override the page_title method

And for regular browsers it would need to override the titleToken method

https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/routes/topic.js.es6#L22

I don’t think there’s a step-by-step guide for these kind of overrides, so if you can manage with the site setting change that would be a lot easier.

4 Me gusta

Hola David, ¡perdona por tardar tanto en responder a esto!

Acabo de crear un plugin para sobrescribir el método page-title, pero el nombre del sitio sigue agregándose al final (cualquier adición que haga simplemente se inserta antes del final), así que parece que se está agregando en otro lugar.

¿Podría ser esto:

  <% content_for(:title) { @title || "#{gsub_emoji_to_unicode(@topic_view.page_title)} - #{SiteSetting.title}" } %>

En views/topics/show.html.erb?

Creé un plugin para sobrescribir todo el archivo show.html.erb, pero no pasó nada. (Tampoco puedo probar con JS desactivado en mi máquina de desarrollo; solo obtengo una página en blanco, ¿es eso normal? Edición: publicado aquí)

Respondí en ese tema; espero que, una vez que eludes Ember CLI, todo funcione como se espera. Si no es así, háznoslo saber.

2 Me gusta

Me pregunto si hay algo en los planes o si es algo que sigue sin estar en la lista actual de implementaciones activas.

Estoy de acuerdo con la mayoría de los títulos del comportamiento predeterminado y también me gustaría poder elegir específicamente algunos de ellos.

Si no hay planes actuales al respecto, ¿existe alguna guía sobre dónde empezar para personalizarlo correctamente?