Set a new value for $key => $value using WordPress shortcode_atts

I’m trying to change a value in a $key => $value pair but I can’t seem to get it working.

$atts = shortcode_atts( array(
            "type"     => FALSE,
            "size"     => FALSE
        ), $atts );


print_r($atts);

Output:

Read More
Array
(
    [type] => default
    [size] => default
)

if ( $atts['size'] == 'default' ) {
    $atts['size'] == false;
}

print_r($atts);

Output:

Array
(
    [type] => default
    [size] => default
)

Basically, what I want to do is, if “size” is “default”, then reset the value to false or an empty string. What am I doing wrong?

Related posts

Leave a Reply

1 comment

  1. You didn’t assigned the variable! See:

    $atts['size'] == false;
                //^^ See here, you don't assign anything
    

    You have to remove one = so it looks like this:

    $atts['size'] = false;
    

    Also i would use var_dump here, because if you assign false and you use print_r the output would be:

    Array ( [type] => default [size] => ) 
    

    With var_dump you see it better:

    array(2) { ["type"]=> string(7) "default" ["size"]=> bool(false) }