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

Function Reference/shortcode atts


Combines user shortcode attributes with known attributes and fills in defaults when needed. The result will contain every key from the known attributes, merged with values from shortcode attributes.


<?php shortcode_atts$pairs$atts$shortcode ); ?>


(array) (required) Entire list of supported attributes and their defaults
Default: None
(array) (required) User defined attributes in shortcode tag
Default: None
(string) (optional) Shortcode name to be used by the shortcode_atts_{$shortcode} filter. If this is present, it makes a "shortcode_atts_$shortcode" filter available for other code to filter the attributes. It should always be included for maximum compatibility, however it is an optional variable.
Default: None

Return Values

Combined and filtered attribute list.


function bartag_func( $atts ) {
	$atts = shortcode_atts(
			'foo' => 'no foo',
			'bar' => 'default bar',
		), $atts, 'bartag' );

	return 'bartag: ' . $atts['foo'] . ' ' . $atts['bar'];
add_shortcode( 'bartag', 'bartag_func' );

[bartag foo="koala" bar="bears"] outputs the following:
bartag: koala bears

[bartag foo="koala"] outputs the following:
bartag: koala default bar

This creates a "[bartag]" shortcode that supports two attributes: [bartag foo="something" bar="something else"]. Both attributes are optional and will take on default options if they are not provided.


The pairs should be considered to be all of the attributes which are supported by the caller and given as a list. The returned attributes will only contain the attributes in the $pairs list.

If the $atts list has unsupported attributes, then they will be ignored and removed from the final returned list.

Change Log

Source File

shortcode_atts() is located in wp-includes/shortcodes.php.




Shortcode API

See also index of Function Reference and index of Template Tags.