Title: Custom fields question
Last modified: August 19, 2016

---

# Custom fields question

 *  [yerlan](https://wordpress.org/support/users/yerlan/)
 * (@yerlan)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/custom-fields-question-3/)
 * Guys, I have following problem. I want my theme to show thumbnail image for posts
   on my frontpage. For this I have a code:
    ` <img class="thumbnail" src="<?php
   echo get_option('home'); ?>/wp-content/themes/mytheme/img/<?php // this is where
   the custom field prints images for each Feature $values = get_post_custom_values("
   Image"); echo $values[0]; ?>" alt=""/>
 * What do I need to add to make my posts not to show thumbnail images if I don’t
   want them, like “if” “ifelse” something like that?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [Equal](https://wordpress.org/support/users/equalmark/)
 * (@equalmark)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/custom-fields-question-3/#post-1277290)
 * I always use this if else code in order to display my custom fields:
 *     ```
       <?php if ( get_post_meta($post->ID, "your-key-here", true) ) { ?>
   
       <img src="<?php echo get_post_meta($post->ID, "your-key-here", true); ?>" class="thumbnail" alt="Your alt text" />
   
       <?php } else { ?>
   
       <!-- do nothing -->
   
       <?php } ?>
       ```
   
 * This basically first checks to see if the custom field is present. If it is it
   then display it in an img tag to display the image, if not then it does nothing.
   For this to work the custom field value must be the absolute URL of the image.
 *  Thread Starter [yerlan](https://wordpress.org/support/users/yerlan/)
 * (@yerlan)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/custom-fields-question-3/#post-1277335)
 * equalmark!
    Thanks a bunch, man! I have used piece of your code, piece of mine
   and finally found out the right way!
 * All the best!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Custom fields question’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [yerlan](https://wordpress.org/support/users/yerlan/)
 * Last activity: [16 years, 6 months ago](https://wordpress.org/support/topic/custom-fields-question-3/#post-1277335)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
