wordpress-seo icon indicating copy to clipboard operation
wordpress-seo copied to clipboard

OG image tags are not showing the biggest available image when a resized version is used in the content

Open mmikhan opened this issue 2 years ago • 2 comments

Reporter: @leonidasmi From: https://yoast.atlassian.net/browse/IM-2116

OG and twitter (image) should be the biggest available (image)

as per this master rule by @jonoalderson, OG images should be the URL full sized images and not their resized counterparts. We’re currently not doing that when we add a resized image in post content.

Steps to reproduce:

  1. Create a post and upload an image in it. The post should have no feature image for the bug to have an effect (I think)
  2. Select a resized version of it via the image block (thumbnail, medium, large) and NOT use the full size image. For example, select the thumbnail.
  3. Visit the frontend

What we expect:

The OG image tag to be:

<meta property="og:image" content="https://example.com/wp-content/uploads/2023/02/example.png" class="yoast-seo-meta-tag" />

because in the content, we get an image like <img src="https://example.com/wp-content/uploads/2023/02/example-300x300.png" and we have to get its full-size counter part to use in OG image tags

What we got instead:

The OG image tag to be:

<meta property="og:image" content="https://example.com/wp-content/uploads/2023/02/example-300x300.png" class="yoast-seo-meta-tag" />

and that’s not adhering to the OG and twitter (image) should be the biggest available (image).

mmikhan avatar Feb 10 '23 14:02 mmikhan

First investigation results:

  • It seems that in the image-helper line 127 in the get_attachment_image_source method, we might want to check out if we can make it so it ignores sizes and just gets the original size. Maybe with https://developer.wordpress.org/reference/functions/wp_get_original_image_url/. But we need to triple check that this method is only used for generating meta tags and schema (double check this with SEO experts) and not else where. Otherwise introduce a new method.

thijsoo avatar Aug 05 '24 10:08 thijsoo

Maybe also consider https://github.com/Yoast/wordpress-seo/pull/20380/files to see if we can use this code to extract the image ID to get the original URL.

thijsoo avatar Aug 06 '24 09:08 thijsoo