get_post_gallery

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

Description

(string|array) get_post_gallery( (int) $post = 0, (bool) $html = true ); 

Returns (string|array)

Gallery data and srcs parsed from the expanded shortcode.

Parameters (2)

0. $post — Optional. (int)
Post ID or WP_Post object. Default is global $post.
1. $html — Optional. (bool) => true
Whether to return HTML or data. Default is true.

Usage

  1. if ( !function_exists( 'get_post_gallery' ) ) { 
  2. require_once ABSPATH . WPINC . '/media.php'; 
  3.  
  4. // Optional. Post ID or WP_Post object. Default is global $post. 
  5. $post = -1; 
  6.  
  7. // Optional. Whether to return HTML or data. Default is true. 
  8. $html = true; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = get_post_gallery($post, $html); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/media.php  
  1. function get_post_gallery( $post = 0, $html = true ) { 
  2. $galleries = get_post_galleries( $post, $html ); 
  3. $gallery = reset( $galleries ); 
  4.  
  5. /** 
  6. * Filters the first-found post gallery. 
  7. * @since 3.6.0 
  8. * @param array $gallery The first-found post gallery. 
  9. * @param int|WP_Post $post Post ID or object. 
  10. * @param array $galleries Associative array of all found post galleries. 
  11. */ 
  12. return apply_filters( 'get_post_gallery', $gallery, $post, $galleries );