warfare-plugins / social-warfare

This is a public repository for the Social Warfare WordPress plugin created primarily for the purpose of publishing and maintaining a public list of bugs, known issues, and feature requests with the community at large.
35 stars 27 forks source link

Add name attribute to og:image tag #683

Closed nutsandbolts closed 5 years ago

nutsandbolts commented 5 years ago

How to test

  1. In Social Warfare > Display> Social Meta Tags, verify that Show Open Graph tags is ON, and save changes.
  2. Visit a post on the front end. View the page source code.
  3. Search for the keyword og:image. The corresponding <meta> tag should include the attribute name='image'. # original issue

LinkedIn prioritizes oEmbed data over OG tags when deciding what image to use in shares. For any customer with a plugin like Yoast or All in One SEO, oEmbed info in the page will result in a wrong image nearly 100% of the time.

According to LinkedIn's documentation and post inspector we can get around this by adding name:"image" as shown here:

<meta name="image" property="og:image" content="[Image URL here]">

ckmahoney commented 5 years ago

The official Open Graph protocol does not specify anything for a name attribute. However, Andrea's experience as well as this SO post suggest adding the custom name attribute.

ckmahoney commented 5 years ago

This issue has been annotated and is ready for testing.

SquanchyMe commented 5 years ago

I have the meta tag, but no single quotes around it as described.. metaimagestuffs

ckmahoney commented 5 years ago

It shouldn't be missing any quotes... We enclose the attributes in single quotes. Here is what it looks like in my development environment.

screen shot 2019-02-25 at 6 09 59 pm Are there any other meta tag plugins on the site, or is there another place we can see this happening?

This is the corresponding code that generates the meta tags.

https://github.com/warfare-plugins/social-warfare-pro/blob/2c07a2d5c95d1009b98705fe67b6d52b30b18d78/lib/frontend-output/SWP_Pro_Header_Output.php#L403

SquanchyMe commented 5 years ago

Tested on another site and it was the same way - no single-quotes.. It turns out W3TotalCache strips them out in its minification.. Tested the tags and they work, so it looks like all is well.

ckmahoney commented 5 years ago

I just changed the type of quotation back from single quotes to double quotes, hoping this prevents W3 Total Cache from stripping anything out.