WordPress.org

Ready to get started?Download WordPress

Codex

Plugin API/Filter Reference/post gallery

Contents

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 716

Related

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