Filter hook 'post_gallery'

in WP Core File wp-includes/media.php at line 2714

View Source

post_gallery

Filter Hook
Description
Filters the default gallery shortcode output. If the filtered output isn't empty, it will be used instead of generating the default gallery template.

Hook Information

File Location wp-includes/media.php View on GitHub
Hook Type Filter
Line Number 2714

Hook Parameters

Type Name Description
string $output The gallery output. Default empty.
array $attr Attributes of the gallery shortcode.
int $instance Unique numeric ID of this gallery shortcode instance.

Usage Examples

Basic Usage
<?php
// Hook into post_gallery
add_filter('post_gallery', 'my_custom_filter', 10, 3);

function my_custom_filter($output, $attr, $instance) {
    // Your custom filtering logic here
    return $output;
}

Source Code Context

wp-includes/media.php:2714 - How this hook is used in WordPress core
<?php
2709  	 *
2710  	 * @param string $output   The gallery output. Default empty.
2711  	 * @param array  $attr     Attributes of the gallery shortcode.
2712  	 * @param int    $instance Unique numeric ID of this gallery shortcode instance.
2713  	 */
2714  	$output = apply_filters( 'post_gallery', '', $attr, $instance );
2715  
2716  	if ( ! empty( $output ) ) {
2717  		return $output;
2718  	}
2719  

PHP Documentation

<?php
/**
	 * Filters the default gallery shortcode output.
	 *
	 * If the filtered output isn't empty, it will be used instead of generating
	 * the default gallery template.
	 *
	 * @since 2.5.0
	 * @since 4.2.0 The `$instance` parameter was added.
	 *
	 * @see gallery_shortcode()
	 *
	 * @param string $output   The gallery output. Default empty.
	 * @param array  $attr     Attributes of the gallery shortcode.
	 * @param int    $instance Unique numeric ID of this gallery shortcode instance.
	 */
Quick Info
  • Hook Type: Filter
  • Parameters: 3
  • File: wp-includes/media.php
Related Hooks

Related hooks will be displayed here in future updates.