The Gallery shortcode.

This implements the functionality of the Gallery Shortcode for displaying WordPress images on a post.

Signature

gallery_shortcode( $attr )
attr
 (array) Attributes of the shortcode.

Return

(string) HTML content to display gallery.

Source

function gallery_shortcode($attr) {
	$post = get_post();

	static $instance = 0;
	$instance++;

	if ( ! empty( $attr['ids'] ) ) {
		// 'ids' is explicitly ordered, unless you specify otherwise.
		if ( empty( $attr['orderby'] ) )
			$attr['orderby'] = 'post__in';
		$attr['include'] = $attr['ids'];
	}

	// Allow plugins/themes to override the default gallery template.
	$output = apply_filters('post_gallery', '', $attr);
	if ( $output != '' )
		return $output;

	// We're trusting author input, so let's at least make sure it looks like a valid orderby statement
	if ( isset( $attr['orderby'] ) ) {
125 more lines...
WP Trac GitHub

Link here