We at SobizTrend Technology use jetpack WordPress plugin for generating Facebook Meta Data in our WordPress themes. However for the effective management of WordPress link sharing on facebook we had customized plugin in simple way.

  1. Default image for homepage when shared in Facebook

If anyone use jetpack plugin for generating Facebook Meta Data and share homepage link of website (like: http://www.sobiztrend.com/) in facebook then it contains blank image of jetpack. To overcome this issues simply put following peice of code on functions.php (Theme Functions) of WordPress themes.

function fb_home_image( $tags ) {
if ( is_home() || is_front_page() ) {
// Remove the default blank image added by Jetpack
unset( $tags['og:image'] );

$fb_home_img = 'Paste_your_image_URI';
$tags['og:image'] = esc_url( $fb_home_img );
}
return $tags;
}
  1. Default image for WordPress Post when shared in Facebook

If your post contains featured image it will appear while you share it on facebook. If your post doesn’t contains featured image and while you share it on facebook jetpack blank image will appear. You can get logo or, any other default image for post when when share in facebook using following line of code.

add_filter( 'jetpack_open_graph_tags', 'fb_home_image' );
function sobizpress_custom_image( $media, $post_id, $args ) {
if ( $media ) {
return $media;
} else {
$permalink = get_permalink( $post_id );
$url = apply_filters( 'jetpack_photon_url', 'Paste_default_image_URI_here' );

return array( array(
'type' => 'image',
'from' => 'custom_fallback',
'src' => esc_url( $url ),
'href' => $permalink,
) );
}
}
add_filter( 'jetpack_images_get_images', 'sobizpress_custom_image', 10, 3 );