kpumuk / meta-tags

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

How to force "property" as key name for custom tags / hashes? #134

Closed michaelfeihstel closed 7 years ago

michaelfeihstel commented 7 years ago

I'm currently preparing some of my pages with Facebook's Open Graph attributes. Let's take a product for example. Facebook expects product attributes to be defined like this:

<meta property="product:brand" content="Asics">

To generate this I'm using this in my view: set_meta_tag product: { brand: "Asics" }

According to your docs two possible outcomes are possible: Under hashes you mention this should result in a meta tag with property as key name. Under custom meta tags the output is described as using name as key name. Since both hashes and custom tags basically use the same syntax this is confusing. In my case the output is generated with name as key name, however Facebook tells me in its debugger that it expects property key name.

This gem doesn't seem to allow me to specify whether to use name or property. Am I missing something very obvious?

pChaAnthony commented 7 years ago

I have the same request, I am using Facebook's profile type.

snicky commented 7 years ago

Unfortunately, it seems the gem doesn't allow to specify the name_key for meta tags with custom names. If you look into the MetaTags::Renderer, the render_tag method pulls the name_key attribute from the options argument (https://github.com/kpumuk/meta-tags/blob/afcbbc7f16cdf2b00a457cf55cf2ec5508d67994/lib/meta_tags/renderer.rb#L252) which in case of custom meta tags is not passed at all (https://github.com/kpumuk/meta-tags/blob/afcbbc7f16cdf2b00a457cf55cf2ec5508d67994/lib/meta_tags/renderer.rb#L38)

snicky commented 7 years ago

The PR above solves this problem by allowing to specify custom meta tags that should use property attribute instead of name in the config.

Startouf commented 7 years ago

The following warning is given by facebook's debugger for a meta profile:first_name

Meta with name instead of property
The meta tag on the page was specified with name 'profile:first_name', which matches a configured property of this object type. It will be ignored unless specified with the meta property attribute instead of the meta name attribute.
kpumuk commented 7 years ago

Version 2.5.0 released, with proper support for all the Open Graph object types (so for your case it will work out of the box), and an ability to specify which tags should be rendered with property key (see Configuration for details)