Display custom field if it has content or hide if not

Posted by fxg on Stack Overflow See other posts from Stack Overflow or by fxg
Published on 2012-12-19T10:58:29Z Indexed on 2012/12/19 11:03 UTC
Read the original article Hit count: 148

Filed under:
|
|

I'm display a custom field this way:

<div class="blog_text">
    <img src="<?php the_field('imagen_prensa'); ?>" />
</div>

I would like to make the img appear only if the user has uploaded an image, because right now if there is no image appear the symbol of broken image.

I have tried with this but it doesn't work:

<?php if (get_field('imagen_prensa') != ''): ?>
     <img src="<?php the_field('imagen_prensa'); ?>" />
<?php endif; ?>

Any idea on the way to achieve it?

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery