Displaying Images Using A Custom Non-Media Field In WordPress
If you are using a custom field to enter the URL of an image whether it is located on your server or externally, and it is not added as a media attachment, you can display the image using the following code.
For example, if your custom field is a simple text field where you add the URL of an image (“https://mydomain.com/images/my-image.jpg”) rather than upload it via the media uploader, you would call the value using get_post_meta.
get_the_ID is used to get the post ID. Change this if your wp_query uses $post_id or another variable to call the post ID.
Change my_custom_photo to the slug of your custom photo field.
$photo = get_post_meta( get_the_ID(), 'my_custom_photo', true ); // If the image was bulk uploaded using media uploader AND was resized to your image specifications, // uncomment the next line to add the following code to modify according to new size // $photo = str_replace(".jpg", "-320x320.jpg", $photo); echo '<img src="' . $photo . '" alt="' . get_the_title() . '" title="' . get_the_title() . '" />';