WordPress Yoast Seo open graph automatic fetch Avatar from Author Page

I’m trying to create a new og:image for author avatar when the users sharing their author profile page to Facebook, i used wpseo_opengraph_image filter, but when i share the link for the first time the image not showing and in the second time it comes up! when i look to the Inspector i see !!, this is code i’m using

function custom_author_og_image() {
if ( is_author ( ) ) {
$author = get_queried_object();
$image_attributes = get_avatar_url( $author->user_email, 200 );
if ( $image_attributes !== false ) {
return $image_attributes[0];
}
}

}
add_filter(‘wpseo_opengraph_image’, ‘custom_author_og_image’, 10, 0);

Any help please?
if i miss any details please tell me.

Read more here:: WordPress Yoast Seo open graph automatic fetch Avatar from Author Page

Leave a Reply

Your email address will not be published. Required fields are marked *