nystudio107 / craft-seomatic

SEOmatic facilitates modern SEO best practices & implementation for Craft CMS 3. It is a turnkey SEO system that is comprehensive, powerful, and flexible.
https://nystudio107.com/plugins/seomatic
Other
162 stars 68 forks source link

Support for LinkedIn image previews? #1391

Closed lbriet closed 5 months ago

lbriet commented 7 months ago

Is your feature request related to a problem? Please describe.

LinkedIn Post Inspector reports that no meta image tag can be found.

Screenshot 2023-11-30 at 17 11 42

Describe the solution you would like

Based on the link above, it appears LinkedIn is looking for a meta tag with the attribute name="image". Adding it to the og:image tag that DOES get output, should satisfy that requirement, presumably?

Describe alternatives you have considered

Customizing the output of the image meta tags using the AddDynamicMetaEvent Event.

Additional context

I'm no SEO expert, but the name="image" addition does seem odd? Facebook clearly doesn't have any issues, nor does X (nor any other meta tag scraper). Is it a new requirement from LinkedIn? In which case, more SEOmatic users might be helped by the addition? Happy to look into resolving it on our end if there are any conflicts or if it deviates from best/standard SEO practices.

khalwat commented 7 months ago

I'm no SEO expert, but the name="image" addition does seem odd? Facebook clearly doesn't have any issues, nor does X (nor any other meta tag scraper). Is it a new requirement from LinkedIn? In which case, more SEOmatic users might be helped by the addition? Happy to look into resolving it on our end if there are any conflicts or if it deviates from best/standard SEO practices.

It's the first I've heard of it, honestly. It would not be difficult to add it to SEOmatic, though, if that's some requirement they've added.

lbriet commented 5 months ago

Looks like this issue still persists for us with LinkedIn, so I guess their change is permanent. As soon as we specify an SEO image with an SEOMatic field, LinkedIn reports the image as missing. Curiously, when we don't specify one, they determine the sharing image just fine.

Have tried, without success so far, to modify the og:image tag (to include name=image) using the various SEOMatic Events. Can you point me in the right direction where to do so?

khalwat commented 5 months ago

So you can do this now via Twig with something like this:

{% set tag = seomatic.script.get('og:image') %}
{% if tag | length %}
    {% do tag.name("image") %}
{% endif %}

ref: https://nystudio107.com/docs/seomatic/using.html#seomatic-tags-containers

Or you could even do it this way:

{% set tag = seomatic.script.get('og:image') %}
{% if tag | length %}
    {% do tag.tagAttrs({
        "name": "image",
    }) %}
{% endif %}

ref: https://nystudio107.com/docs/seomatic/using.html#extra-tag-attributes

...if this works for you, and solves your issue, I think it makes sense to just bake it into SEOmatic, and fix it that way too, though.

The weird thing to me is that nowhere is the name="image" specified in the OpenGraph protocol:

https://ogp.me/

...which is what LinkedIn in theory uses.

lbriet commented 5 months ago

Ha! Sorry for missing that.. It does work beautifully for adding the attribute (with seomatic.tag. instead of seomatic.script ;) ). Unfortunately (for us) though, LinkedIn still seems to happily ignore the sharing image.

What's even more curious - when using their Post Inspector on a local version of the site (ddev share), they find the image we're trying to set. Not so for the exact same setup on live website. Looked into and tweaked some headers, but no success. To further confuse everything - the image URL they pull is from the on-page <img> tag, and not the one we set in meta..

Thanks for the help in any case, does seems more and more like it's LinkedIn doing strange LinkedIn things that we can't directly control. Will update here if we do manage to find out what's going on.

khalwat commented 5 months ago

Yeah I'm not sure this is actually an issue with SEOmatic. If you find out more information, I'm more than happy to help, debug, and if needed, make changes to SEOmatic.