shortcode_atts

Definition:
function shortcode_atts($pairs, $atts) {}

Combine user attributes with known attributes and fill in defaults when needed.
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.

Parameters

  • array $pairs: Entire list of supported attributes and their defaults.
  • array $atts: User defined attributes in shortcode tag.

Return values

returns:Combined and filtered attribute list.

Source code

function shortcode_atts($pairs, $atts) {

	$atts = (array)$atts;

	$out = array();

	foreach($pairs as $name => $default) {

		if ( array_key_exists($name, $atts) )

			$out[$name] = $atts[$name];

		else

			$out[$name] = $default;

	}

	return $out;

}

2861

No comments yet... Be the first to leave a reply!

Leave a comment