Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've actually been searching on this site for the answer to this question for quite some time. Looking for a way to 'echo/print' multiple og:images for facebook. What I have here used only 'the_post_thumbnail'

function fb_image() {
if (is_single()) {
    global $post;
    $feature_image = get_the_post_thumbnail($post->ID);
    $doc = new DOMDocument();
    $doc->loadHTML($feature_image);
    $imageTags = $doc->getElementsByTagName('img');

    foreach($imageTags as $tag) {
            $image_url = $tag->getAttribute('src');
    }
}
?>

<meta property="og:image" content="<?php echo $image_url; ?>" />
<?php }
add_action('wp_head', 'fb_image');
share|improve this question
1  
where are the images coming from? in what context do you want them added? –  Milo Nov 1 '12 at 18:29
add comment

1 Answer

up vote 1 down vote accepted

Figured it out with

function postimage($size = 'thumbnail', $qty = -1) 
{
    if (is_single() && !is_home() && !wp_attachment_is_image()) {
    global $post;$images = get_children(array(
    'post_parent' => $post->ID,
    'post_type' => 'attachment',
    'posts_per_page' => $qty,
    'post_mime_type' => 'image')
);    if ( $images ) {
        foreach( $images as $image ) {
            $attachmenturl = wp_get_attachment_url($image->ID);
            $attachmentimage = wp_get_attachment_image( $image->ID, $size );
            echo '<meta property="og:image" content="'.$attachmenturl.'"/>';
        }
    } else {
        echo "No Image";
    }
}
}    
add_action('wp_head', 'postimage');
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.