Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the wpseo_opengraph_image_size filter to select a specific image size does not output an og:image tag. #19448

Closed
BobBreukhoven opened this issue Dec 21, 2022 · 0 comments · Fixed by #19693
Assignees

Comments

@BobBreukhoven
Copy link
Contributor

BobBreukhoven commented Dec 21, 2022

https://yoast.atlassian.net/browse/DUPP-857

It’s a popular issue based on the number if bug reports we have received so far from many different users. I made a complete list for you:

wpseo_opengraph_image_size custom size is ignored once post is saved in wp_yoast_indexable table (since 16.2)COMPONENT: OPENGRAPH

IM-2033: wpseo_opengraph_image should run (even) if there's no image setNEW

wpseo_opengraph_image_size custom size is ignored once post is saved in wp_yoast_indexable table (since 16.2)COMPONENT: OPENGRAPH

Issues with custom FB image sizes & og:image tagsCOMPONENT: SOCIAL

Changing the og:image for Custom Post Type archive pagesTYPE: FEATURE REQUEST

Not always able to use wpseo_opengraph_image filter for adding og:imageCOMPONENT: HOOKS

We’ve received a report from a customer saying that they are using the wpseo_opengraph_image_size filter to select a specific image size for their og: images. However, this causes the og:image tag not to be added to the page.

The customer is using the following filter:

// Add custom image size for Yoast SEO socials
add_image_size( 'featured-full', 1200, 800 );
add_filter( 'wpseo_opengraph_image_size', 'yoast_seo_opengraph_change_image_size' );
function yoast_seo_opengraph_change_image_size() {
return 'featured-full';
}

A similar issue was previously reported here: twitter:image not being output at all, and og:image tag is ignoring wpseo_opengraph_image_size filterWAIT FOR FEEDBACK

More details from the user:

In WPSEO_Image_Utils::get_image, image_get_intermediate_size method returns the image array for the particular size. But in case there's no image for that size, which can happen in 2 cases:

the image is too small

the image is the same size as the size being asked for.

My case is the latter. So the size does exist but since the original file is the same as the size setting, no additional file has been created. eg.

https://insidehook-com-preprod.go-vip.net/wp-content/uploads/2022/02/hero-1.jpeg
Is the same as the required size "featured-full" - 1200x800. Hence no additional image has been created by WP.

In the above case, image_get_intermediate_size( $id, 'featured-full') return false! And hence no image is returned to g:image!

The customer has also added some workarounds they have implemented manually in the plugin core to fix this issue:

FTI, this is the hack I added to your code that helped resolve this issue for me (this is not added to the above server though so you can test properly):

FTI, this is the hack I added to your code that helped resolve this issue for me (this is not added to the above server though so you can test properly):

public static function get_image( $attachment_id, $size ) {
$image = false;
if ( $size === 'full' ) {
$image = self::get_full_size_image_data( $attachment_id );
}

if ( ! $image ) {
$image = image_get_intermediate_size( $attachment_id, $size );

/* THIS HAS BEEN ADDED AS A HACK TO PREVENT LOADING INLINE IMAGE AS OG IMAGE!

  • This bug should be logged with Yoast to avoid overwriting during next update
  • See https://github.com/42-18/Integrated-Platform/issues/652
    /
    if ( ! is_array( $image) ) {
    $att = wp_get_attachment_image_src( $attachment_id, $size );
    $image = array();
    $image['url'] = $att[0];
    $image['width'] = $att[1];
    $image['height'] = $att[2];
    }
    $image['size'] = $size;
    /
    END HACK */

}

if ( ! $image ) {
return false;
}

$image['size'] = $size;

return self::get_data( $image, $attachment_id );

The customer has lots more details in HelpScout ticket number 869467

@BobBreukhoven BobBreukhoven changed the title Improve link in schema metabox, depending on the Post Type Using the wpseo_opengraph_image_size filter to select a specific image size does not output an og:image tag. Dec 21, 2022
@vraja-pro vraja-pro self-assigned this Jan 20, 2023
@thijsoo thijsoo assigned thijsoo and unassigned vraja-pro Jan 23, 2023
@enricobattocchi enricobattocchi modified the milestone: 20.1 Jan 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants