Support » Plugins » [Plugin: Custom Field Template] only get img url when using WYSIWYG

  • Hello, just got my copy of the Custom Field Template plug-in and it’s so nice! I was wondering if it’s possible for me to modify some code so that when you choose an image from the WYSIWYG interface, only the img url gets pasted into the field, and not the full HTML for displaying that image.

    The reason for this is because I’ve been using echo to display my thumbnail from the custom field, that way, I have the flexibility to change the image size:

    <?php if(get_post_meta($post->ID, "thumbnail", true)) { ?>
    	<img src="<?php echo get_post_meta($post->ID, "thumbnail", true); ?>" alt="" width="<?php echo $width; ?>" height="<?php
    	echo $height; ?>" />
    	<?php } ?>

    I really appreciate any help anybody offers. Thank you!

Viewing 1 replies (of 1 total)
  • Surely, its simple

    Add this function in your themes functions.php

    function get_image_url($image_content) {
    
    				$st = strpos($image_content,'src="')+5;
    				$ed = strpos($image_content,'"',$st)-$st;
    				$ret_image_content = substr($image_content,$st,$ed);
    				return $ret_image_content;
    }

    and then modify your code as

    <?php if(get_post_meta($post->ID, "thumbnail", true)) { ?>
    	<img src="<?php echo get_image_url(get_post_meta($post->ID, "thumbnail", true)); ?>" alt="" width="<?php echo $width; ?>" height="<?php
    	echo $height; ?>" />
    	<?php } ?>

    Guess it helped you.

Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Custom Field Template] only get img url when using WYSIWYG’ is closed to new replies.