Forums

Adding custom image to Facebook (6 posts)

  1. baal666
    Member
    Posted 2 weeks ago #

    Hi,

    I'd like to add a custom image to the Facebook link. Right now each image on each of my post is too big for Facebook to consider it. I'd like to find a way to make a smaller version that would show on Facebook link. I can do one for the who blog that would be linked from the header, but I'd like that image to change depending on the post.

    Any idea?

    Thanks

  2. baal666
    Member
    Posted 2 weeks ago #

    Anyone?

  3. baal666
    Member
    Posted 2 weeks ago #

    Maybe my question is not clear enough.

    Ok, let me reformulate.

    I already show wide images on my blog, but they are too big to be taken care of by facebook. I am looking for a way to integrate images to Facebook links for each of my posts. Any idea?

  4. baal666
    Member
    Posted 2 weeks ago #

    My image is 650 px width... is it why Facebook does not take it? How can I do anything to go around this?

    Facebook documentation

    says that this in the header would work:

    <link rel="image_src" href="http://www.onjd.com/design05/images/PH2/WableAFC205.jpg" />

    But how to make that link change each time there is a new post and link to another smaller version of the bigger image?

  5. timnicholson
    Member
    Posted 2 weeks ago #

    bal, try using the WP built-in function to get the thumbnail version of the image. You can set the size of the thumbnail that WP will create when you upload the image on your post.

    The code should look something like this:

    //Get images attached to the post
    $args = array(
    	'post_type'      => 'attachment',
    	'post_mime_type' => 'image',
    	'numberposts'    => -1,
            'order'          => 'ASC',
    	'post_status'    => null,
    	'post_parent'    => $post->ID
    );
    $attachments = get_posts($args);
    if ($attachments) {
    	foreach ($attachments as $attachment) {
    		$img = wp_get_attachment_thumb_url( $attachment->ID );
    echo '<link rel="image_src" href="'.$img.'">';
                    break;
            }

    Also check out this function, which could be used to pull the "medium" or "large" version of the uploaded image:
    http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src

  6. baal666
    Member
    Posted 1 week ago #

    The problem is that I don't want the thumbnail to get displayed; I want regular visitors to see my 650 width pix... Smaller image is only for Facebook.

Reply

You must log in to post.

About this Topic