Title: get_post_gallery_images
Published: April 25, 2014
Last modified: February 24, 2026

---

# get_post_gallery_images( int|WP_Post $post ): string[]

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_post_gallery_images/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/functions/get_post_gallery_images/?output_format=md#see-also)
 * [Parameters](https://developer.wordpress.org/reference/functions/get_post_gallery_images/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_post_gallery_images/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_post_gallery_images/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_post_gallery_images/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_post_gallery_images/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_post_gallery_images/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_post_gallery_images/?output_format=md#wp--skip-link--target)

Checks a post’s content for galleries and return the image srcs for the first found
gallery.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_post_gallery_images/?output_format=md#description)󠁿

### 󠀁[See also](https://developer.wordpress.org/reference/functions/get_post_gallery_images/?output_format=md#see-also)󠁿

 * [get_post_gallery()](https://developer.wordpress.org/reference/functions/get_post_gallery/)

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_post_gallery_images/?output_format=md#parameters)󠁿

 `$post`int|[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
optional

Post ID or [WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
object. Default is global `$post`.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_post_gallery_images/?output_format=md#return)󠁿

 string[] A list of a gallery’s image srcs in order.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_post_gallery_images/?output_format=md#source)󠁿

    ```php
    function get_post_gallery_images( $post = 0 ) {
    	$gallery = get_post_gallery( $post, false );
    	return empty( $gallery['src'] ) ? array() : $gallery['src'];
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/media.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/media.php#L5458)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/media.php#L5458-L5461)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_post_gallery_images/?output_format=md#related)󠁿

| Uses | Description | 
| [get_post_gallery()](https://developer.wordpress.org/reference/functions/get_post_gallery/)`wp-includes/media.php` |

Checks a specified post’s content for gallery and, if present, return the first

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_post_gallery_images/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.6.0](https://developer.wordpress.org/reference/since/3.6.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_post_gallery_images/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/get_post_gallery_images/?output_format=md#comment-content-606)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/get_post_gallery_images/#comment-606)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_gallery_images%2F%23comment-606)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_gallery_images%2F%23comment-606)
 4.  **Example**
      A simple example of how to append the raw image URLs to the content
     of any post or page that has at least one gallery.
 5.      ```php
          add_filter( 'the_content', 'wpdocs_show_gallery_image_urls' );
     
         /**
          * Show image URLs below the content
          */
         function wpdocs_show_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->post_content, 'gallery' ) )
         		return $content;
     
         	// Retrieve the first gallery in the post
         	$gallery = get_post_gallery_images( $post );
         	$image_list = '<ul>';
     
         	// Loop through each image in each gallery
         	foreach( $gallery as $image_url ) {
         		$image_list .= '<li>' . '<img src="' . $image_url . '">' . '</li>';
         	}
         	$image_list .= '</ul>';
     
         	// Append our image list to the content of our post
         	$content .= $image_list;
     
         	return $content;
          }
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_gallery_images%2F%3Freplytocom%3D606%23feedback-editor-606)
 7.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/get_post_gallery_images/?output_format=md#comment-content-6092)
 8.    [MaFt](https://profiles.wordpress.org/maft/)  [  4 years ago  ](https://developer.wordpress.org/reference/functions/get_post_gallery_images/#comment-6092)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_gallery_images%2F%23comment-6092)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_gallery_images%2F%23comment-6092)
 10. This does not work if the gallery type is set to ‘slideshow’. It returns nothing.
     Removing type=”slideshow” from the gallery shortcode allows the images to be picked
     up by this function.
 11.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_gallery_images%2F%3Freplytocom%3D6092%23feedback-editor-6092)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_gallery_images%2F)
before being able to contribute a note or feedback.