0

i am trying to make nested if else shortcode but its not working. any one please help as soon as possible.

function fn_services_text_box($attr){

$name           = $attr['service_name'];
$icon           = $attr['icon_path'];
$text           = $attr['content_text'];
$link           = $attr['url_path'];

$output         = if($icon == ''){
                    $output        .='<div class="service-list-title"><h3>'.$name.'</h3></div>
                    <div class="service-list-txt">'.$text.'</div>                                    
                    <div class="service-list-readmore"><a href="'.$link.'">Know More</a></div>';
                }
                else if($link == ''){
                    $output        .='<div class="polygon-shape">
                        <div class="icon">
                            <img class="img" src="'.$icon.'" />
                        </div>
                    </div>
                    <div class="service-list-title"><h3>'.$name.'</h3></div>
                    <div class="service-list-txt">'.$text.'</div>  '; 
                }
                else{
                    $output        .='<div class="polygon-shape">
                        <div class="icon">
                            <img class="img" src="'.$icon.'" />
                        </div>
                    </div>
                    <div class="service-list-title"><h3>'.$name.'</h3></div>
                    <div class="service-list-txt">'.$text.'</div>                                    
                    <div class="service-list-readmore"><a href="'.$link.'">Know More</a></div>';
                }

return $output;

}

i am usig this short code in visual composer by adding it to shortcode mapper.

1 Answers1

2

Please replace this line

$output = if($icon == ''){

to

$output = "";
if($icon == ''){
Vaibhavi S.
  • 1,083
  • 7
  • 20
  • 1
    it worked like magic thanks alot . can u please explain why you did this $output == ""; – Poonam Katpara Aug 26 '19 at 11:35
  • 1
    Most Welcome @PoonamKatpara Let me explain, We can not directly declare variable $output with if statement. so we need to first declare variable empty like `$outout = ""` then if else statment we can append data like you already did. – Vaibhavi S. Aug 26 '19 at 11:38