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
  • What does $attr contain? Doat your function return anything? Commented Aug 26, 2019 at 12:02

1 Answer 1

2

Please replace this line

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

to

$output = "";
if($icon == ''){
Sign up to request clarification or add additional context in comments.

2 Comments

it worked like magic thanks alot . can u please explain why you did this $output == "";
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.