Ok, it's Wordpress related and that i learn about Wordpress Stack Exchange, but I am asking here since this is mostly a PHP question.

I would like my code to show something or free using if statement.

The issue is I am going to possess a variable and bloginfo('template_directory') in-bulit function.

I authored this:

    <?php if (!empty($instance['example'])) 

    echo "<li><a href=". $example ."><img src="?><?php bloginfo('template_directory') ?><?php echo "/images/example.png /></a></li>"; ?>   

It really works fine until $instance['example'] isn't empty, just when was - still it shows web site directory link including images/example.png.

Any ideas?

I have attempted " . bloginfo('template_directory') . " but does not appear to operate.

PHP if claims that don't have braces is only going to assess the first line after that. To solve this,

 <?php if (!empty($instance['example']))  {

echo "<li><a href=". $example ."><img src="?><?php bloginfo('template_directory') ?><?php echo "/images/example.png /></a></li>"; } ?> 

Try might find out if it really works to your requirements. All Used to do was place the braces to ensure that your if statement spans all your arguments.

You didn't remember to include the : following the if statement to create an if endif; block. Alternatively make use of the standard curly brackets to surround all of your instructions within the if statement.

Presently it's only checking if for that first echo command.

Do this code:

<?php if (!empty($instance['example'])) 

    echo "<li><a href=". $example ."><img src=".get_bloginfo('template_directory')."/images/example.png /></a></li>";
?>   

Do this

<?php if (!empty($instance['example'])) {

    echo "<li><a href=". $example ."><img src="?><?php bloginfo('template_directory') ?>
    <?php echo "/images/example.png /></a></li>"; 

   }
?>

I would use.

<?php 
if( !empty( $instance['example'] ) )
    echo '<li><a href="' . $example . '"><img src="' . get_bloginfo('stylesheet_directory') . '/images/example.png" alt="" border="0" /></a></li>'; 
?>

First we add individuals missing attribute quotes.
Second we make use of the stylesheet road to ensure it indicates the right location for a kid theme.
Third we call get_bloginfo to obtain a return value for that echo statement.
4th, i additionally added a border="0" towards the image, edges aren't usually wanted to have an image in the link as well as added an alt tag, since it will a minimum of help pass HTML validation, even when you depart it empty.

Same answer as others, however with better formatted code:

<?php 
if(!empty($instance['example']))
{
    echo '<li><a href=' . $example . '><img src=' . bloginfo('template_directory') . '/images/example.png /></a></li>'; 
}
?> 

Added brackets, removed unnecessary opening/closing php tags, and converted strings to single quotes since you will find no variables or special figures contained within them that require processing.