Forums

[resolved] problem with image associated with url when sharing (2 posts)

  1. giant slayer
    Member
    Posted 7 months ago #

    I am having trouble assigning/defining a specific image I want associated with a url when it is shared.

    I have a weekly post that is automatically generated each week. I also have this post automatically shared to my personal facebook wall and fan page for my art.

    The image facebook pulls is not the one I want. I have embeded the following tags in the head section of the post.

    <link rel="image_src" type="image/jpeg" href="http://theviolent.net/wp-content/themes/slayer/ipadthumb/autumn-glory.jpg" />
    <meta property="og:image" content="http://theviolent.net/wp-content/themes/slayer/ipadthumb/autumn-glory.jpg" />

    This is the image I want.
    This is what gets picked up if I visit the post and then manually share, but it is not getting this image when the post is automatically posted to word press and then to facebook.

    Anyone have any ideas how I can define the image associated with the url at the time of the post?

    Thank you,
    christopher

  2. giant slayer
    Member
    Posted 6 months ago #

    I found a work around by attaching an image and assigning it to be the featured image/post thumbnail. Here is the code.

    $new_post_id=wp_insert_post( $my_post );
    $filename='/wp-content/themes/slayer/ipadthumb/' . sprintf("%s", $freebackgrounds->background[$i]->imagefilename);
    $wp_filetype = wp_check_filetype(basename($filename), null );
    $attachment = array(
       'post_mime_type' => $wp_filetype['type'],
       'post_title' => preg_replace('/\.[^.]+$/', '', basename($filename)),
       'post_content' => '',
       'post_status' => 'inherit'
    );
    $attach_id = wp_insert_attachment( $attachment, $filename, 37 );
    wp_publish_post( $new_post_id );

Reply

You must log in to post.

About this Topic