Checks a specified post’s content for gallery and, if present, return the first
Parameters
Source
* @param int|WP_Post $post Optional. Post ID or WP_Post object. Default is global $post.
* @param bool $html Optional. Whether to return HTML or data. Default is true.
* @return string|array Gallery data and srcs parsed from the expanded shortcode.
*/
function get_post_gallery( $post = 0, $html = true ) {
$galleries = get_post_galleries( $post, $html );
$gallery = reset( $galleries );
/**
* Filters the first-found post gallery.
*
* @since 3.6.0
*
* @param array $gallery The first-found post gallery.
* @param int|WP_Post $post Post ID or object.
Changelog
Version | Description |
---|---|
3.6.0 | Introduced. |
If there is no gallery present in the page, the function will return
false
(boolean).Example
Output each image in a gallery with our own custom image class when using data output and not HTML:
Example data output