OG image tags are not showing the biggest available image when a resized version is used in the content
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:
- 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)
- 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.
- 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).
First investigation results:
- It seems that in the
image-helperline 127 in theget_attachment_image_sourcemethod, 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.
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.