WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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();
    $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
where are the images coming from? in what context do you want them added? – Milo Nov 1 '12 at 18:29
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

Your Answer


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.