简体   繁体   中英

Removing The IMG SRC tag in Wordpress

I'm trying to remove the "img src" tag from the php so it'll simply display the images url, rather than displaying the actual image. This is the code I've got so far and it works perfectly, but when it's rendered it shows thumbnails instead of urls.

<?php $pics = get_post_meta( $post->ID, 'pics', true ); 
    foreach( $pics as $pics) 
    {
        $image_attributes = wp_get_attachment_image_src( $pics['pictures'] );
        echo '<img src="' . $image_attributes[0] . '" />';
    }
?>

I know theres a way to do this, but I don't know how to remove the tags without breaking the image code. Any help is appreciated.

If you just want to echo the image src and not display it as an image then change

echo '<img src="' . $image_attributes[0] . '" />';

to

 echo $image_attributes[0];

<?php 

    $pics = get_post_meta( $post->ID, 'pics', true ); 
    foreach( $pics as $pics) 
    {
        $image_attributes = wp_get_attachment_image_src( $pics['pictures'] );
        echo $image_attributes[0];
    }

?>

So do you want to show on the page the "html code" with the tag and the src attribute?

Have you tried to enclose "img" tag within "pre" tag?

echo '<pre><img src="' . $image_attributes[0] . '" /></pre>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM