Web Hosting
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix Reply To: Image thumbnail not showing for social sharing of posts

Discussion in 'Misc WordPress Requests' started by Jaydeep Jagani, Oct 30, 2017.

  1. Jaydeep Jagani

    Guest

    Reply To: Image thumbnail not showing for social sharing of posts, by Jaydeep Jagani

    Hello @akinleyeajayi

    If Yoast plugin is not working then you can try with a custom code to add a meta image for facebook share.

    Here is the code that you can copy and paste into your theme’s functions.php file.


    function insert_og_image_in_head() {
    global $post;
    if(!has_post_thumbnail( $post->ID )) { //the post does not have featured image, use a default image
    $default_image= get_template_directory_uri()."/images/defaultshareimage.jpg"; //replace this with a default image on your server or an image in your media library
    echo '<meta property="og:image" content="' . $default_image . '"/>';
    }
    else{
    $thumbnail_src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' );
    echo '<meta property="og:image" content="' . esc_attr( $thumbnail_src[0] ) . '"/>';
    }
    }
    add_action( 'wp_head', 'insert_og_image_in_head', 5 );

    This will help you. also let me know if you have still issue or not getting anything in this.

    Reply To: Image thumbnail not showing for social sharing of posts
     
    #1

Share This Page

Web Hosting