0

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.

3
  • can you do var_dump($image_attributes); and show us the output? Commented Jun 3, 2015 at 13:08
  • 1
    why dont you simple use echo $image_attributes[0]; Commented Jun 3, 2015 at 13:09
  • $image_attributes[0] worked, thanks Ash. I know it seems kind of noob, but Im just learning PHP lol. Thanks alot everyone for the help. Commented Jun 3, 2015 at 15:36

2 Answers 2

2

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];
    }

?>
Sign up to request clarification or add additional context in comments.

Comments

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>';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.