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.
Works based on: get_post_gallery()
1 time = 0.0064108s = very slow | 50000 times = 81.22s = very slow | PHP 7.3.12, WP 5.3.2
No Hooks.
Return
Array. 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
- See: get_post_gallery()
Changelog
Since 3.6.0 | Introduced. |
Code of get_post_gallery_images() get post gallery images WP 5.6
function get_post_gallery_images( $post = 0 ) {
$gallery = get_post_gallery( $post, false );
return empty( $gallery['src'] ) ? array() : $gallery['src'];
}