Hello Theogk,
I am sorry about the issue you experienced with the plugin, but I cannot reproduce this. I created a new post and did not set an image; the default image I have set in Yoast SEO > Social > Facebook was picked up automatically as the og:image.
Often, we see problems occur in combination with another plugin or theme. The fastest way to rule out any conflict is to deactivate all non-Yoast plugins and switch to a standard theme like Twenty Twenty.
Please test this on your development or staging site if you have one. If not, we recommend using the Health Check & Troubleshooting plugin. This plugin has a troubleshooting mode, which does not affect normal visitors to your site.
If you’re unfamiliar with checking for conflicts, we’d like to point you to a step-by-step guide that will walk you through the process: How to check for plugin conflicts
If you feel uncomfortable doing this yourself or if this does not solve your issue, our Yoast SEO Premium plugin comes with one year of (technical) support.
Hello, please read my post more carefully about the conditions when this problem appears.
These 2 things must be true at the same time for the problem to appear.
1. NO featured image set
2. Post content includes an image, inserted with a GT block or elementor.
Then the og:image is not the default from the settings, but the image included in the content.
Thanks
Hey @theogk,
Thank you for your reply.
What you describe is actually the order of how our plugin uses images for social platforms, this has not changed recently.
This is the order:
– A user-defined image “Facebook image” in the Social tab of the Yoast metabox on the post/page level.
– A user-defined “Featured image” for the page (only for posts).
– A prominent image from the page’s content.
– The “Social default image” from the template in Search Appearance.
– The site’s fallback/default social image (set at SEO > Social > Facebook > Default image).
Hope this helps to clarify.
Hmmm, this was not the way it worked in the past, maybe I noticed the change just now.
Is there a way (with code I guess) to skip the “prominent image from the page’s content” and use the “Social default image” image instead? It is creating so many problems with unwanted images in all the wrong dimensions, causing odd croppings on social sharing.
Thanks
@theogk There isn’t a way to set this behavior globally in the way you described, but there are a number of filters documented in the plugin code for developers to programmatically change OpenGraph output.
You can find some example usage of these filters available here.
For anyone looking to do the same thing, I wrote this code that seems to work fine:
// if og:image is set from a random content image, change it to default og:image from yoast settings
add_filter( 'wpseo_opengraph_image', 'dc_yoast_prefer_default_image_over_first_content_image', 10, 2 );
function dc_yoast_prefer_default_image_over_first_content_image( $img_url, $presentation ) {
if ( !empty( $presentation ) && isset( $presentation->model ) && isset( $presentation->model->open_graph_image_source ) ) {
if ( 'first-content-image' === $presentation->model->open_graph_image_source ) {
$yoast_options = get_option( 'wpseo_social' );
if ( !empty( $yoast_options['og_default_image'] ) ) {
return trim( $yoast_options['og_default_image'] );
}
}
}
return $img_url;
}