WordPress.org

Ready to get started?Download WordPress

Forums

WordPress SEO by Yoast
Default image for Open Graph breaks when Facebook plugin activated (5 posts)

  1. rilwis
    Member
    Posted 1 year ago #

    Hi,

    In the latest version of WordPress SEO plugin, I see Yoast uses a filter fb_meta_tags to change the open graph meta tags. It works nicely, except one thing: the default image set in the plugin settings page doesn't work, because Facebook will get only the thumbnail image.

    I made a quick fix for this, and applied in one of my site, it's working. Here it is:

    add_filter( 'fb_meta_tags', 'bc_fb_image' );
    
    /**
     * Add default image open graph meta when both Facebook & WordPress SEO plugins activated
     *
     * @param array $meta_tags
     *
     * @return array
     */
    function bc_fb_image( $meta_tags )
    {
    	if ( !empty( $meta_tags['http://ogp.me/ns#image'] ) )
    		return $meta_tags;
    
    	$wpseo_option = get_option( 'wpseo_social' );
    
    	if ( empty( $wpseo_option['og_default_image'] ) )
    		return $meta_tags;
    
    	$image = array( 'url' => $wpseo_option['og_default_image'] );
    
    	$meta_tags['http://ogp.me/ns#image'] = array( $image );
    
    	return $meta_tags;
    }

    I hope Yoast can include this feature in the next version of the plugin, because I see the WordPress SEO has more options for OG image (featured image, first image in the content, and the default image) than the Facebook plugin.

    http://wordpress.org/extend/plugins/wordpress-seo/

  2. mystus
    Member
    Posted 1 year ago #

    I'm experiencing a very similar problem - Where exactly did you put this code of yours?

  3. rilwis
    Member
    Posted 1 year ago #

    In my functions.php of the theme.

  4. Pepperbase
    Member
    Posted 1 year ago #

    @rilwis Thanks for the example of the fb_meta_tags filter. Had to do some customization and got it working now.

  5. lucasrcosta
    Member
    Posted 1 year ago #

    Any news on this?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic