Is there a way to get all parameters in the WordPress shortcode?
For example,
function bartag_func( $atts ) {
$a = shortcode_atts(
array(
'foo' => 'something',
'bar' => 'something else',
),
$atts);
return "foo = {$a['foo']}";
}
add_shortcode('bartag', 'bartag_func');
Here [bartag]
is shortcode.
Is there a way to know the values of shortcode_atts
or value of foo
bar
, etc.?
Is there a way to get all variable values inside the bartag_func
?
You can use this function to get all values from shortcode:
function bartag_func( $atts ) {
$atts = shortcode_atts(
array(
'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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With