Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get post galleries images


Retrieves an array of image URLs that belong to galleries added to the specified post.


(Post ID or object.) (required) The post to look in.
Default: None


A multidimensional array of image URLs.


 <?php  $galleries get_post_galleries_images$post ); ?> 


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.

 function pw_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 all galleries of this post
 	$galleries = get_post_galleries_images( $post );

	$image_list = '<ul>';

	// Loop through all galleries found
	foreach( $galleries as $gallery ) {

		// Loop through each image in each gallery
		foreach( $gallery as $image ) {

			$image_list .= '<li>' . $image . '</li>';



	$image_list .= '</ul>';

	// Append our image list to the content of our post
	$content .= $image_list;

 	return $content;

 add_filter( 'the_content', 'pw_show_gallery_image_urls' );

Change Log

Source File

get_post_galleries_images() is located in wp-includes/media.php.


get_post_galleries(), get_post_gallery_images()

This article is marked as in need of editing. You can help Codex by editing it.