• Resolved Theo Gkitsos

    (@theogk)


    Hello! I have a problem with the default og:image option in your settings (Yoast->Social->Facebook).

    The problem appears when there is no featured image set AND an image exists in the post/page content (happens in both Gutenberg and Elementor). In this case, the default image from your settings doesn’t appear on the og:image tag, but a random image from the content appears instead. See image-> https://prnt.sc/WkaO7CVLSdGO

    -If I set a featured image, then the og:image shows correctly.
    -If there is no image in the content, then the default og:image from your settings appears.

    I’m using the latest version of Yoast (19.6.1)

    Thanks

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Support Maybellyne

    (@maybellyne)

    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.

    Thread Starter Theo Gkitsos

    (@theogk)

    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.

    Thread Starter Theo Gkitsos

    (@theogk)

    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

    Plugin Support devnihil

    (@devnihil)

    @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.

    Thread Starter Theo Gkitsos

    (@theogk)

    Ok thanks

    Thread Starter Theo Gkitsos

    (@theogk)

    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;
    }
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Default og:image setting doesn’t work anymore’ is closed to new replies.