Defaults - aaemnnosttv/shortcode-alias-api GitHub Wiki

One of the most powerful features exposed by the api is the ability to pre-define default values for alias shortcode attributes and content.

Defaults are passed as an array when the alias is registered. The array follows this basic structure:

array(
    'atts' => array(),
    'content' => ''
)

Simple Defaults

Simple defaults are just that - if no value was passed, the default is applied in it's place. Otherwise, the shortcode-passed value is used as usual.

array(
    'atts' => array(
        'attribute_name' => 'some default value',
        'foo' => 'bar'
    ),
    'content' => 'this is the default inner content'
)

Note: There is no difference to the shortcode's callback function between a default-passed value and a shortcode-passed value. The shortcode will behave the same as if the default was passed in the shortcode itself.

Complex Defaults

Complex defaults allow for more control over the value. In a way, they can become more than just a simple default, but more like modifiers.

A complex default is defined as an array instead of a simple string.

The same example as above could be achieved like so:

array(
    'atts' => array(
        'attribute_name' => array('default' => 'some default value'),
        'foo' => array('default' => 'bar')
    ),
    'content' => array('default' => 'this is the default inner content')
)

This would be impractical though as it's significantly more to type, for the same result. This is why there is a simple syntax.

Complex Default Value Syntax

array(
	'default' => '', // behaves the same as the simple default value
	'prepend' => '', // prepend the shortcode-passed value with this
	'append'  => '', // append the shortcode-passed value with this
	'override'=> '', // override the shortcode-passed value completely with this
)

Defaults are applied using the provided filters made available for every shortcode alias.