Title: Insert image from custom field path?
Last modified: August 21, 2016

---

# Insert image from custom field path?

 *  [j4ze](https://wordpress.org/support/users/j4ze/)
 * (@j4ze)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/insert-image-from-custom-field-path/)
 * Is it possible to create a loop, that does something similar to this:
 * if
    [customfield-value] is not empty then insert image src: ../images/customfield-
   value.jpg else insert image src: ../images/default.jpg end
 * Narrowing it down to questions:
    1. can i make the custom field part of my img
   src path? 2. my custom field value will be containing spaces – will that result
   in a problem?
 * Eksample: I have a custom field with the value of a name etc “John Smith”, i 
   have manually uploaded a thumbnail picture to my server (../images/) called “
   John Smith.jpg”, now i want to display that picture. However if the custom field
   does not contain a name (=null), then i just want to display a default thumbnail(..
   images/default.jpg).
 * Hope it makes sense and that some of you guys can help me 🙂

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

 *  Thread Starter [j4ze](https://wordpress.org/support/users/j4ze/)
 * (@j4ze)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/insert-image-from-custom-field-path/#post-4288331)
 * So far i’ve come up with this code
 *     ```
       <?php if get_post_meta( $post->ID, 'CUSTOMFIELD', true)!=null {
       				<div id="authThumb"><img src="../fluxichild/images/<?php echo get_post_meta( $post->ID, 'CUSTOMFIELD', true );?>.jpg"/></div>
       				}else {
       					div id="authThumb"><img src="../fluxichild/images/defaultAuth.jpg" /></div>
       				}
       				?>
       ```
   
 * but to no surprise, it doesn’t work, I know i have a syntax error somewhere, 
   but i hardly think thats the only mistake 😀
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [12 years, 5 months ago](https://wordpress.org/support/topic/insert-image-from-custom-field-path/#post-4288335)
 * corrected for syntax errors:
 *     ```
       <?php if( get_post_meta( $post->ID, 'CUSTOMFIELD', true)!=null ) { ?>
       				<div id="authThumb"><img src="../fluxichild/images/<?php echo get_post_meta( $post->ID, 'CUSTOMFIELD', true ); ?>.jpg"/></div>
       				<?php } else { ?>
       					<div id="authThumb"><img src="../fluxichild/images/defaultAuth.jpg" /></div>
       				<?php } ?>
       ```
   
 * relative image paths might not work properly;
    in this case try for example: `
   <img src="<?php echo get_stylesheet_directory_uri(); ?>/images/defaultAuth.jpg"/
   >` [http://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri](http://codex.wordpress.org/Function_Reference/get_stylesheet_directory_uri)

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

The topic ‘Insert image from custom field path?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Michael](https://wordpress.org/support/users/alchymyth/)
 * Last activity: [12 years, 5 months ago](https://wordpress.org/support/topic/insert-image-from-custom-field-path/#post-4288335)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
