WordPress at a glance

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.009867s = very slow | 50000 times = 544.97s = extremely slow | PHP 7.0.4, WP 4.4.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: wp-includes/media.php WP 5.2.4

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

Related Functions

From tag: Gallery

vladlu 100vlad.lu
Editors: kama 100
No comments
    Hello, !     Log In . Register