WordPress at Your Fingertips

get_post_gallery_images() WP 3.6.0

Retrieves an array of image URLs that belong to the first gallery of the specified post.

There is a similar function get_post_galleries_images() which retrieves all galleries, not only the first one.

Gets the URLs of the thumbnails, not of the full-size images.

1 time — 0.0064108 sec (very slow) | 50000 times — 81.22 sec (very slow) | PHP 7.3.12, WP 5.3.2

No Hooks.

Return

String[]. A list of a gallery's image srcs in the order they are listed in the [gallery] shortcode.

Usage

get_post_gallery_images( $post );
$post(int|WP_Post)
Post ID or WP_Post object.
Default: global $post

Examples

#1 Basic usage

$gal = get_post_gallery_images( 2179 );

/* $gal contains
Array
(
	[0] => http://wp-kama.com/wp-content/uploads/2016/02/image12-80x80.png
	[1] => http://wp-kama.com/wp-content/uploads/2016/02/image11-80x80.png
	[2] => http://wp-kama.com/wp-content/uploads/2016/02/image10-80x80.png
)
*/

Notes

Changelog

Since 3.6.0 Introduced.

Code of get_post_gallery_images() WP 5.8.1

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

Gallery

vladlu 100vlad.lu
Editors: Kama 101
No comments
    Log In