title: Get image caption in Wordpress
body: <p>I have this code to retrieve the image url for the images in a gallery and it works ok but i cannot figure out how i could get the caption for each image.</p>
  
  <p>I tried searching all over but i cannot seem to put all the information out there together! Any suggestions on how i could retrieve the captions? </p>
  
  <pre><code> function show_related_gallery_image_urls( $content ) {
  
      global $post;
  
      // Only do this on singular items
      if( ! is_singular() )
          return $content;
  
      // Make sure the post has a gallery in it
      if( ! has_shortcode( $post-&gt;post_content, 'gallery' ) )
          return $content;
  
  
  
      // Retrieve all galleries of this post
      $galleries = get_post_galleries_images( $post );
  
      $image_list = &lt;&lt;&lt;END
                      &lt;div class="side_bar"&gt;
              &lt;div class="related"&gt;
                  &lt;h3&gt;Related Images&lt;/h3&gt;
  END;
  
      // Loop through all galleries found
      foreach( $galleries as $gallery ) {
  
          // Loop through each image in each gallery
          foreach( $gallery as $image ) {
  
              $src = $image;
  
              $image_list .=  '&lt;a href="' . $src . '" rel="' . get_the_title() . '"&gt;' 
                                  . '&lt;img src="' . $src .'" /&gt;' 
                              . '&lt;/a&gt;';
  
          }
  
      }
  
      $image_list .= '&lt;/div&gt;&lt;/div&gt;';
  
      // Append our image list to the content of our post
      $content .= $image_list;
  
      return $content;
  
   }
   add_filter( 'the_content', 'show_related_gallery_image_urls' );
  </code></pre>
  
  <p>I hope i explained myself well! Thanks!</p>