don't display shortcode attribute if empty… easier way?
-
Hello,
I have a shortcode… that I have been using.. So my issue is that if one of the attributes is empty.. i don’t want it to display the html once the page is published ( when viewsource or other methods are used)
Question is:
1. is there a way or check to do it for all the attributes at once? instead of writing if else if statements?
2 if not is there a proper method that doesn’t require lots of if statements?
Basically in the code I have posted..
if type is empty , not to display any part of the
<i class="fa fa-"'.$type.'"></i>function demo_item_box( $atts, $content = null ) { extract(shortcode_atts(array( 'image' => '', 'title' => '', 'type' => '', 'link' => '', 'linktitle' => 'Read more', 'target' => '_blank', ), $atts)); $output = '<div class="test_box">'; if( $link ) $output .= '<a href="'. $link .'">'; $output .= '<img src="'. $image .'" alt="'. $title .'" />'; if( $link ) $output .= '</a>'; $output .= '</div>'; $output .= '<div class="desc">'; $output .= '<i class="fa fa-"'.$type.'"></i>'.'<h4>' . $title .'</h4>'; $output .= '<p>'. do_shortcode( $content ) .'</p>'; $output .= '</div>'; $output .= '</div>'; return $output; } add_shortcode("test", "demo_test_box");
The topic ‘don't display shortcode attribute if empty… easier way?’ is closed to new replies.