WordPress shortcode parameters

Is there a way to get all parameters in the WordPress shortcode?

For example,

Read More
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?

Related posts

1 comment

  1. 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

Comments are closed.