I am looking for a way to reproduce what is described in the documentation: An overloaded shortcode callback.
According to the docs, the $atts
array will contain the string that matched the shortcode RegEx. The position inside $atts
depends on if the callback name matches the shortcode or not. The following example is taken from the docs:
add_shortcode('foo','foo'); // two shortcodes referencing the same callback
add_shortcode('bar','foo');
produces this behavior:
[foo a='b'] ==> callback to: foo(array('a'=>'b'),NULL,"foo");
[bar a='c'] ==> callback to: foo(array(0 => 'bar', 'a'=>'c'),NULL,"");
So I registered my shortcodes like this:
add_shortcode('foo', 'foo');
add_shortcode('bar', 'foo');
function foo($attributes, $content = null) {
echo '<pre>';
var_dump($attributes);
echo '</pre>';
}
Unfortunately, $attributes is always empty, it does not contain the name of the shortcode (WP 4.0).
Is this an error in the documentation or am I going wrong somewhere?