Overriding Attributes values in Shortcode Plugins

I have made some shortcode plugins according to my need. But this time I am getting a strange problem. My attributes in the shortcode are not getting the values written in the shortcode while executing them, instead I am just getting the default set values only. Please Help me.

add_shortcode('wi_form' , 'wi_form_func');

function wi_form_func($input) {
    extract(shortcode_atts( array(
        'productName'  => 'Java',
        'productPrice' => 1000
    ), $input));
    return $productName . esc_attr($productPrice);
}

Related posts

1 comment

  1. Try not to use capital letters in the shortcode attributes, use for example

    [wi_form product_name="php" product_price="888" ]
    

    where:

    add_shortcode( 'wi_form' , 'wi_form_func' );
    
    function wi_form_func($input) {
        extract(shortcode_atts( array(
            'product_name'  => 'Java',
            'product_price' => 1000
        ), $input));
        return $product_name . esc_attr( $product_price );
    }
    

    or this:

    add_shortcode( 'wi_form' , 'wi_form_func' );
    
    function wi_form_func($input) {
        $input = shortcode_atts( array(
            'product_name'  => 'Java',
            'product_price' => 1000
        ), $input );
        return $input['product_name'] . esc_attr( $input['product_price'] );
    }
    

    if you don’t want to use extract:

    Update:

    The shortcode attributes go through strtolower() in the shortcode_parse_atts() function that retrieves them from the shortcode tag (see here).

Comments are closed.