get_post_gallery() WordPress Function

The get_post_gallery() function displays the images attached to a post, if there are any. The function can be used with or without arguments. If no arguments are passed, the function displays all of the images attached to the post. If arguments are passed, the function displays only the images that match the specified criteria.

get_post_gallery( int|WP_Post $post, bool $html = true ) #

Check a specified post’s content for gallery and, if present, return the first


Parameters

$post

(int|WP_Post)(Optional) Post ID or WP_Post object. Default is global $post.

$html

(bool)(Optional) Whether to return HTML or data. Default is true.

Default value: true


Top ↑

Return

(string|array) Gallery data and srcs parsed from the expanded shortcode.


Top ↑

Source

File: wp-includes/media.php

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 );
}


Top ↑

Changelog

Changelog
VersionDescription
3.6.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More