Removing else; what to do with if?

I would like to remove the else statement in the following code.

How shall I convert the if statement, so it still works (route is correct/ logo is being shown)?

<div class="logo a">
        <a href="<?=$site_url;?>">
            <?php if(isset($settings['site_logo_image']) && $settings['site_logo_image'] != '') { ?>
                <img src="<?=$site_url;?>_img/logo.png" class="image_logo" border="0" height="40" alt="<?=(isset($settings['site_logo']) ? $settings['site_logo'] : 'Hello');?>" />
            <?php } else { ?>
                        <?=(isset($settings['site_logo']) ? $settings['site_logo'] : 'Hello');?>
            <?php } ?>
        </a>
</div>

If I leave out the if prefix, it’s not working.
I am not a pro in php and actually have to do with frontend stuff…

Thanks

>Solution :

It’s a bit tricky to read php interspersed with HTML. Once you get the knack of it, though, it’s straightforward. Delete everything from else { to the next }. Like this.

<div class="logo a">
  <a href="<?=$site_url;?>">
    <?php if(isset($settings['site_logo_image']) && $settings['site_logo_image'] != '') { ?>
      <img src="<?=$site_url;?>_img/logo.png" class="image_logo" border="0" height="40" alt="<?=(isset($settings['site_logo']) ? $settings['site_logo'] : 'Hello');?>" />
    <?php }  ?>
  </a>
</div>

Pro tip A language-aware IDE like VSCODE or PhpStorm will alert you immediately if you make a mistake doing this sort of thing.

Leave a Reply