Support

Account

Home Forums General Issues Image field as content returns only the url

Helping

Image field as content returns only the url

  • hi there

    I have set up a custom image field for top level pages. It returns the url to the image.

    Is there a hack which will make it possible to use the title, description and alt fields when attaching a new image in a page ?

    Cheers,
    Adam

  • If you want to display an image tag you’re best choice is to set the field to return the attachment id, then use that to call one of the WP functions to get the image. The easiest way would probably be http://codex.wordpress.org/Function_Reference/wp_get_attachment_image

    
    $attachment_id = get_field('my_image_field');
    if ($attachment_id) {
      $size = 'full'; // set to the defined image size you want
      $image_tag = wp_get_attachment_image($attachment_id, $size);
      if ($image_tag) {
        echo $image_tag;
      }
    }
    
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.