Forums

Custom Fields - How to Display Default Image? (4 posts)

  1. bmg1227
    Member
    Posted 4 years ago #

    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.

  2. wp_guy
    Member
    Posted 4 years ago #

    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; ?>
  3. bmg1227
    Member
    Posted 4 years ago #

    Worked beautifully - thanks SO much for saving me time!

  4. CFCnet
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.