[Plugin: Custom Field Template] can you config the template to just insert the IMAGE URL ? (2 posts)

  1. bftechdez2001@gmail.com
    Posted 6 years ago #

    I am using a custom field to insert the url of an image and that is used as a post image. Is there a way to have the custom field template just insert the URL of the image from the media browser ?

    Or is there a way to strip the image code that is inserted from the media browser to just get the image URL?

    Thanks I would LOVE this.

    And thank you for your plugin... I am a happy donator.

  2. humjay
    Posted 6 years ago #

    I solved this by using some regex in my template to detect if the output was a full image tag or just a url like so:

    if( get_post_meta($post->ID, 'images')):
    $images = get_post_meta($post->ID, 'images'); 
    foreach($images as $image):
    if(strpos($image, "<img") !== FALSE):
      preg_match('/src=[\"\']([^\"\']+)/i', $image, $matches);
      $imageurl = $matches[1];
      $imageurl = $image;

    You can then use the imageurl variable wherever you need the source. This code will let someone just paste in the url or use the media library to insert a full image.

Topic Closed

This topic has been closed to new replies.

About this Topic