WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Filter Reference/post gallery

This page is marked as incomplete. You can help Codex by expanding it.

Description

Allows plugins and themes to override the default gallery template, ie. what the gallery shortcode returns.

Examples

Hook into the gallery shortcode and replace its output with your own.

function my_gallery_shortcode( $output = '', $atts = null, $instance = null ) {
	$return = $output; // fallback

	// retrieve content of your own gallery function
	$my_result = get_my_gallery_content( $atts );

	// boolean false = empty, see http://php.net/empty
	if( !empty( $my_result ) ) {
		$return = $my_result;
	}

	return $return;
}

add_filter( 'post_gallery', 'my_gallery_shortcode', 10, 3 );

Parameters

$output
(string) (required) The current output - the WordPress core passes an empty string.
Default: ""
$atts
(array) (required) The attributes from the gallery shortcode.
Default: None
$instance
(int) (required) Unique numeric ID of this gallery shortcode instance.
Default: None

Triggers

This function is applied once, in wp-includes/media.php - in gallery_shortcode() on line 1648

Related