WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Custom Field Template] only get img url when using WYSIWYG (2 posts)

  1. lanlan
    Member
    Posted 5 years ago #

    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!

  2. suril.bhagat
    Member
    Posted 5 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic