-
Notifications
You must be signed in to change notification settings - Fork 874
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
Wrong image width and height when using "wpseo_opengraph_image" filter #15052
Wrong image width and height when using "wpseo_opengraph_image" filter #15052
Comments
I was able to reproduce this. As a workaround I would normally advise Please note that this behavior is not new in 14.0, but was present in 13.5 as well. Steps to reproduce:
|
Tried to fix this in my specific case by creating a class that extends use Yoast\WP\SEO\Presenters\Open_Graph\Image_Presenter;
class MyPresenter extends Image_Presenter {
protected function filter( $image ) {
$image_url = \trim( \apply_filters( 'wpseo_opengraph_image', $image['url'], $this->presentation ) );
if ( ! empty( $image_url ) && \is_string( $image_url ) ) {
$image['url'] = $image_url;
$image['width'] = 500;
$image['height'] = 500;
}
return $image;
}
} However, this didn't work either. After debugging, I can see that the From this, I think we can deduce that if meta keys are set twice, only the first value is output to the page. |
The code below worked in 13.5 but not in 14.1
|
Please inform the customer of conversation # 613628 when this conversation has been closed. |
On testing Yoast 14.2, and with my If I remove my Multiple |
FWIW, the way I got it to work (which is quite cursed) is to filter the presenter and override the function issue15052_yoast_presentation($presentation) {
global $post;
if (isset($post)) {
$presentation->open_graph_images = [
[
'url' => $your_image_url,
'width' => 1200,
'height' => 630,
'type' => 'image/png'
]
];
}
return $presentation;
}
add_filter('wpseo_frontend_presentation', 'issue15052_yoast_presentation', 30); |
I am also having this issue. Don't know if it's been solved. For a certain post type, I'm setting the facebook og:image programmatically not using an image in the media library. I've been able to set the og:image but the width and height of the default image is still shown.
Tried the following with no luck:
|
I modified a @markspolakovs solution to my needs, so I will share it here if it helps anyone. It fetches the featured image, checks for minimum Facebook dimensions and sets all of the parameters. function change_yoast_image($presentation) { global $post; if (isset($post)) { $img_id = get_post_thumbnail_id($post->ID); if ($img_id) { $image_url = wp_get_attachment_url($img_id); // get image sizes and type list($width, $height, $type) = getimagesize($image_url); // minimum pixels for sharing (Facebook is 200px) if ($width > 200 && $height > 200) { $presentation->open_graph_images = [ [ 'url' => $image_url, 'width' => $width, 'height' => $height, 'type' => $type ] ]; } } } return $presentation; } add_filter('wpseo_frontend_presentation', 'change_yoast_image', 30); |
@markspolakovs solution works for me. In case that you want to change the Twitter image. $presentation->twitter_image = {your_image_url} p/s: I don't know why from v14.1 Yoast SEO does not allow developers to filter the open graph image width and height. |
+1 Has anyone found the solution for it? @cheba91 solution seems to be working for me, I will run some more tests, but I was wondering if anyone has any other suggestions. |
Are there any updates planned? I noticed that When a developer uses the |
After some internal discussion we decided on going for investigating the use of the |
When providing custom image using "wpseo_opengraph_image" filter:
display wrong width and height, i.e. not using the ones from the image provided.
The text was updated successfully, but these errors were encountered: