title: Show image description/caption in WordPress
body: <p>When I try to get the caption or description from a image in wordpress it's not working. I can't find a real answer. I tried so many things but I don't know where i have to put some of the code. I read that I had to put this in <code>functions.php</code>:</p>
  
  <pre><code>function wp_get_attachment( $attachment_id ) {
  
  $attachment = get_post( $attachment_id );
  return array(
  'alt' =&gt; get_post_meta( $attachment-&gt;ID, '_wp_attachment_image_alt', true ),
  'caption' =&gt; $attachment-&gt;post_excerpt,
  'description' =&gt; $attachment-&gt;post_content,
  'href' =&gt; get_permalink( $attachment-&gt;ID ),
  'src' =&gt; $attachment-&gt;guid,
  'title' =&gt; $attachment-&gt;post_title
  );
  }
  
  $attachment_meta = wp_get_attachment(your_attachment_id);
  </code></pre>
  
  <p>and this in my loop:</p>
  
  <pre><code>&lt;?php echo $attachment_meta['caption']; ?&gt;
  </code></pre>
  
  <p>Like this:</p>
  
  <pre><code>&lt;section&gt;
   &lt;div class="container"&gt;
    &lt;div class="row"&gt;
     &lt;?php 
     if( class_exists('Dynamic_Featured_Image') ):
     global $dynamic_featured_image;
     global $post;
     $featured_images = $dynamic_featured_image-&gt;get_featured_images( $post-&gt;ID );
     if ( $featured_images ):
    ?&gt;
    &lt;?php foreach( $featured_images as $images ): ?&gt;
    &lt;div class="col-md-4 col-sm-4 col-xs-12"&gt;
     &lt;img src="&lt;?php echo $images['full'] ?&gt;" alt="" class="img-responsive"&gt;
     &lt;?php echo $attachment_meta['caption']; ?&gt;
    &lt;/div&gt;
   &lt;?php endforeach; ?&gt;
   &lt;?php
   endif;
  endif;
  ?&gt; 
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/section&gt;
  </code></pre>
  
  <p>What am I doing wrong?</p>