Reputation: 55
I want to run an if statement on an attribute in my shortcode but for some reason it wont work?
I know that the attribute is being passed through because when I echo it were 'working' currently is I see the value so not sure what's wrong with my if statement?
if ( $atts['type'] == 'Platinum' ) {
?>
<h2><?php echo 'working'?></h2>
<?php
} else {}
Upvotes: 0
Views: 745
Reputation: 390
You can use shortcode attributes like below.
<?php
function function_name($atts) {
extract(shortcode_atts(array(
'var1' => 'value1', //Assigning default value
'var2' => 'value2',
), $atts));
if($var1 == 'Platinum'){
//Do things
} else {
//Do other things
}
}//Function ends
add_shortcode('shortcode_name', 'function_name');
Upvotes: 1