WordPress.org

Ready to get started?Download WordPress

Codex

Attention 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, $content = false, $tag = false ) {
	$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, 4 );

Parameters

$empty
(string) (required) Currently always passed as
Default: None
$attr
(array) (required) The attributes from the gallery shortcode
Default: None

Triggers

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

Related