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

Function Reference/shortcode atts gallery


Provides the ability to filter the array returned from shortcode_atts(). Within your plugin, you can take the default shortcode attributes, the user supplied attributes, and the merged array of those two into account prior to shortcode_atts() returning.

Potential uses:

  • Override the default shortcode attributes (in a fashion)
  • Ignore certain attribute values from the user and instead use the defaults
  • Dynamically generate shortcode attribute values
  • Modifying the behavior of a shortcode handler via attributes without redefining and rewriting the handler, particularly if the shortcode handler doesn't present filters of its own

This would be particularly useful to modify the behavior of core-supplied shortcodes.


(array) (required) The shortcode_atts() merging of $defaults and $atts
Default: None
(array) (required) The default attributes defined for the shortcode
Default: None
(array) (required) The attributes supplied by the user within the shortcode
Default: None

Return Value

The potentially modified $result array


Exclude post thumbnail image from gallery if user doesn't explicitly exclude any images

add_filter( 'shortcode_atts_gallery', 'gallery_shortcode_exclude_thumbnail', 10, 3 );
function gallery_shortcode_exclude_thumbnail( $result, $defaults, $atts ) {
	if ( empty( $atts['exclude'] ) )
		$result['exclude'] = get_post_thumbnail_id();
	return $result;


see Trac Ticket


Since 3.1