I would like to display data from a post that has custom fields in a metabox. One of the fields is the URL for an image. How do I create an echo to display the image?

The other field I want to call is a link. I have one field for the URL and one field for the link text. How do I echo this to diplay the link.



  • Did either of our answers give you what you needed? If so, go ahead and click the "check mark" icon by one of our answers. Thanks 14ner! – Jonathan Wold May 26 '11 at 15:40

Within your Query loop, using your image URL as an example, put this:

<?php $image_url = get_post_meta($post->ID, 'image-url-field', true); ?>

Replace "image-url-field" with the name of your custom field.

Then, also within that same loop, do this:

<?php echo $image_url; ?>

Reference: http://codex.wordpress.org/Function_Reference/get_post_meta


I think what we want might be something more like:

  $image_url = get_post_meta($post->ID, 'image-url-field', true);
  $link_url = get_post_meta($post->ID, 'link-url-field', true);
  $link_text = get_post_meta($post->ID, 'link-text-field', true);

  // display inline image
  echo '<img src="' . esc_url($image_url) . '" />';

  // display clickable link
  echo '<a href="' . esc_url($link_url) . '">' . esc_html($link_text) . '</a>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy