WordPress.org

Support

Support » How-To and Troubleshooting » [Plugin: Custom Field Template] can you config the template to just insert the IMAGE URL ?

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

  • 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.

Viewing 1 replies (of 1 total)
  • 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];
    else:
      $imageurl = $image;
    endif;

    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.

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Custom Field Template] can you config the template to just insert the IMAGE URL ?’ is closed to new replies.
Skip to toolbar