What to do if I do not see Sharing Image poster on Facebook or Twitter #
If you generated a poster but don't see it, it's likely that some other plugin or your theme is also displaying image tags.
Use snippets for popuplar plugins and themes to replace poster image.
Yoast SEO Plugin
add_filter( 'sharing_image_hide_meta', '__return_true' );
function my_add_opengraph_images( $image_container ) {
$sharing_image = sharing_image_poster_src();
$updated_image = array(
'url' => $sharing_image[0],
'width' => $sharing_image[1],
'height' => $sharing_image[2],
);
$image_container->add_image( $updated_image );
};
add_action( 'wpseo_add_opengraph_images', 'my_add_opengraph_images' );
The SEO Framework Plugin
/**
* @link https://kb.theseoframework.com/kb/filter-reference-for-the-seo-framework/#image-related
*/
add_filter( 'the_seo_framework_image_generation_params', 'my_image_generation_params', 10, 3);
function my_image_generation_params( $params = [], $args = null, $context = 'social' ) {
if ( 'social' !== $context ) {
return $params;
}
if ( null === $args ) {
if ( is_singular( 'post' ) ) {
$params['cbs']['custom'] = 'my_sharing_image_poster';
}
} else {
if ( ! $args['taxonomy'] ) {
$params['cbs']['custom'] = 'my_sharing_image_poster';
}
}
return $params;
}, 10, 3 );
function my_sharing_image_poster( $args = null, $size = 'full' ) {
$post_id = $args['id'] ?? the_seo_framework()->get_the_real_ID();
$sharing_image = sharing_image_poster_src( $post_id );
if ( $sharing_image ) {
yield [
'url' => $sharing_image[0],
];
} else {
yield [
'url' => '',
'id' => 0,
];
}
}
Props to Mikhail Kobzarev