title: Display custom field if it has content or hide if not
body: <p>I'm displaying a custom field like this:</p>
  
  <pre><code>&lt;div class="blog_text"&gt;
      &lt;img src="&lt;?php the_field('imagen_prensa'); ?&gt;" /&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I would like to make the img appear only if the user has uploaded an image, because right now if there is no image then a broken image symbol appears.</p>
  
  <p>I have tried the following, but it did not work:</p>
  
  <pre><code>&lt;?php if (get_field('imagen_prensa') != ''): ?&gt;
       &lt;img src="&lt;?php the_field('imagen_prensa'); ?&gt;" /&gt;
  &lt;?php endif; ?&gt;
  </code></pre>
  
  <p>Any can this be achieved?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>this is the code now using the answers below but now it gives just a blank page:</p>
  
  <pre><code>&lt;div id="blog_interior"&gt;
  
          &lt;?php /* Start the Loop */ ?&gt;
          &lt;?php while ( have_posts() ) : the_post(); ?&gt;
  
              &lt;article&gt;
              &lt;div class="article_date"&gt;&lt;?php the_time('d/m/Y'); ?&gt;&lt;/div&gt;
              &lt;h2&gt;&lt;?php echo get_the_title(); ?&gt;&lt;/h2&gt;
              &lt;div class="blog_text"&gt;
                  &lt;?php if ( !empty(the_field('imagen_prensa')) ): ?&gt;
                      &lt;img src="&lt;?php echo the_field('imagen_prensa'); ?&gt;" /&gt;
                  &lt;?php endif; ?&gt;
                  &lt;div class="video_prensa"&gt;&lt;?php the_field('video_prensa'); ?&gt;&lt;/div&gt;
                  &lt;?php the_content() ?&gt;
              &lt;/div&gt;
          &lt;/article&gt;
  
          &lt;?php endwhile; ?&gt;    
              &lt;div class="back"&gt;
  
              &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>