• I’m currently using custom fields to display thumbnails on my homepage. Here is the code I am using below:

    <img src="<?php echo get_post_meta($post->ID, "Thumbnail", true); ?>" alt="alt text" />

    Basically what I want to know is how to display a default image should custom field be left blank and an image is not specified.

Viewing 3 replies - 1 through 3 (of 3 total)
  • I haven’t tried but something like this should work:

    <?php if( get_post_meta($post->ID, "Thumbnail", true) ): ?>
        <img src="<?php echo get_post_meta($post->ID, "Thumbnail", true); ?>" alt="alt text" />
    <?php else: ?>
        <img src="default.jpg" alt="alt text" />
    <?php endif; ?>
    Thread Starter bmg1227

    (@bmg1227)

    Worked beautifully – thanks SO much for saving me time!

    Can a default image be displayed if an image is not found?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Fields – How to Display Default Image?’ is closed to new replies.