Conditional: if has_post_thumbnail

Fundamental 450 views
+1
0 Flares 0 Flares ×

If some of your posts have a thumbnail and some not, you can use this to put a placeholder in place on the posts with no post thumbnail.

<?php if ( has_post_thumbnail()) { ?>

<?php } else { ?>

<?php } ?>

Use Case

<?php if ( has_post_thumbnail()) { ?>
    <?php the_post_thumbnail(); ?>
<?php } else { ?>
    <img src="<?php bloginfo('template_directory'); ?>/images/filler.jpg" alt="Filler Picture" />
<?php } ?>
Tagged with: ,
Posted in Wordpress

Discuss:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

No Trackbacks.

Login

Register | Lost your password?
0 Flares Twitter 0 Facebook 0 Google+ 0 0 Flares ×