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

Fallback OG image Twitter Image unexpected results #12996

Open
2 tasks done
carasmo opened this issue May 21, 2019 · 2 comments
Open
2 tasks done

Fallback OG image Twitter Image unexpected results #12996

carasmo opened this issue May 21, 2019 · 2 comments

Comments

@carasmo
Copy link

carasmo commented May 21, 2019

  • I've read and understood the contribution guidelines.
  • I've searched for any related issues and avoided creating a duplicate issue.

Please give us a description of what happened.

Expected results:

  1. I have a fallback OG image in the Yoast settings.
  2. When I don't have a featured image on that page, then both twitter and og get the url.

Strange results:

  1. I have a fallback OG image in the Yoast settings.
  2. If there is a featured image BUT it's not displayed on the page (used for archives) then the OG image is the fallback but the Twitter image is the featured image assigned but not displayed.

What I would expect is that both the OG and the Twitter image get the featured image whether or not it's displayed on the page.

Please describe what you expected to happen and why.

See above.

How can we reproduce this behavior?

See first.

Technical info

Latest all. Not using Gutenberg. N/A.

@carasmo
Copy link
Author

carasmo commented May 21, 2019

This is my slapped together work around.

add_filter( 'wpseo_opengraph_image', 'filter_wpseo_opengraph_image', 10, 1 ); 
/**
 * Opengraph Social Image from Featured Image
 * If user does not enter a social image AND the page has a featured image, use that
 * otherwise use the default assigned in settings.
 * Won't work unless a default image is set via the settings in Yoast.
 */
function filter_wpseo_opengraph_image( $img ) { 
        
  	global $post;
	
	if( isset( $post ) && has_post_thumbnail() ) :
		
		$og = get_post_meta( $post->ID, '_yoast_wpseo_opengraph-image', true ); 
				
		if ( empty( $og ) ) :
			$img = get_the_post_thumbnail_url( $post->ID, 'facebook-instagram'  );
		else: 
			$img = $og;
		endif;
		
	endif;
  
    return $img; 
    
} 


add_filter( 'wpseo_twitter_image', 'filter_wpseo_twitter_image', 10, 1 ); 
/**
 * Twitter Social Image from Featured Image
 * If user does not enter a social image AND the page has a featured image, use that
 * otherwise use the default assigned in settings.
 */
function filter_wpseo_twitter_image( $img ) { 
        
  	global $post;
	
	if( isset( $post ) && has_post_thumbnail() ) :
		
		$tw = get_post_meta( $post->ID, '_yoast_wpseo_twitter-image', true ); 
				
		if ( empty( $tw ) ) :
			$img = get_the_post_thumbnail_url( $post->ID, 'facebook-instagram'  );
		else: 
			$img = $tw;
		endif;
		
	endif;
  
    return $img; 
    
} 

@Djennez
Copy link
Member

Djennez commented Jun 7, 2019

Hi @carasmo, thanks for your report and analysis. The Twitter and Facebook meta images are calculated via different systems and I agree that this causes strange behavior. I'll ask our product team to determine if this is something that we want to change so that they behave more consistently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants