get_post_gallery( int|WP_Post $post, bool $html = true ): string|array
Checks a specified post’s content for gallery and, if present, return the first
Parameters
Return
string|array Gallery data and srcs parsed from the expanded shortcode.
Source
File: wp-includes/media.php
.
View all references
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.
* @param array $galleries Associative array of all found post galleries.
*/
return apply_filters( 'get_post_gallery', $gallery, $post, $galleries );
}
Hooks
-
apply_filters( 'get_post_gallery',
array $gallery ,int|WP_Post $post ,array $galleries ) -
Filters the first-found post gallery.
Changelog
Version | Description |
---|---|
3.6.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.
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