kpumuk / meta-tags

Search Engine Optimization (SEO) for Ruby on Rails applications.
MIT License
2.73k stars 275 forks source link

Fallback to site_name if title unspecified in `og`? #242

Closed philipithomas closed 2 years ago

philipithomas commented 2 years ago

Here's my use case:

If a page's title is not specified, then I'd like to show the og:title as the site name.

I can't just set <% title: 'site name' %> because that results in <title>site name | site name</title>

How might I do this? (Can I replace :title with some kind of a method call so that I can trigger a fallback?)

The reason is my site homepage. Of all links on the site, the homepage is most likely to be shared. But, Twitter meta tag validations unless a twitter:title / og:title is set.

philipithomas commented 2 years ago

How I'm temporarily solving this:

<% og_title = @page_title || "site name" %>
<%= display_meta_tags og: { title: og_title } %>
kpumuk commented 2 years ago

Nice case, thank you for reporting it. Would you mind trying out a branch to see if it solves your problem?

gem "meta_tags", git: "https://github.com/kpumuk/meta-tags", branch: "mirror-empty-title"
philipithomas commented 2 years ago

@kpumuk Yes, exactly. Thank you!

philipithomas commented 2 years ago

Thanks for the prompt fix!

kpumuk commented 2 years ago

Just released, 2.18.0 with this change. Thanks again