admin管理员组文章数量:1130349
I have a strange problem, when I try to enter the source of an image tag using PHP it shows me the following error in the inspector
<img src=(unknown) alt="">
this code fragment gives me the correct url, checked by seeing the CPanel and pasting and copying the address,but when I try to enter it via php the image is not shown
$image = wp_get_attachment_image_src( $post_thumbnail_id);
//echo($image[0]);
?>
<img src="<?php $image[0]; ?>" alt="">
The next thing I did was an echo of image[0] and it gave me the url of the image, I copied it and pasted it in the tag and that's when it showed me the image
<img src="mysite/wp-content/uploads/2018/11/957a...150x150.jpg" alt="">
I saw the page in Incognito Window and I did not show the image either.
Any clues?
I have a strange problem, when I try to enter the source of an image tag using PHP it shows me the following error in the inspector
<img src=(unknown) alt="">
this code fragment gives me the correct url, checked by seeing the CPanel and pasting and copying the address,but when I try to enter it via php the image is not shown
$image = wp_get_attachment_image_src( $post_thumbnail_id);
//echo($image[0]);
?>
<img src="<?php $image[0]; ?>" alt="">
The next thing I did was an echo of image[0] and it gave me the url of the image, I copied it and pasted it in the tag and that's when it showed me the image
<img src="mysite/wp-content/uploads/2018/11/957a...150x150.jpg" alt="">
I saw the page in Incognito Window and I did not show the image either.
Any clues?
Share Improve this question asked Nov 21, 2018 at 0:59 TraukoTrauko 251 silver badge6 bronze badges2 Answers
Reset to default 0I think that you need echo the image, try this:
<php
$image = wp_get_attachment_image_src( $post_thumbnail_id );
//echo( $image[0] );
?>
<img src="<?php echo $image[0]; ?>" alt="">
If you only want the URL of the image, use wp_get_attachment_image_url(). It saves you having to do the [0] thing:
<img src="<?php echo wp_get_attachment_image_url( $post_thumbnail_id ); ?>" alt="">
However, if you want to output an image tag for an attachment, you're much better off using wp_get_attachment_image():
echo wp_get_attachment_image( $post_thumbnail_id, 'full' );
This will give you the full <img> tag, but including the alt text, width & height attributes, and srcset attribute. The alt text in particular is important.
I have a strange problem, when I try to enter the source of an image tag using PHP it shows me the following error in the inspector
<img src=(unknown) alt="">
this code fragment gives me the correct url, checked by seeing the CPanel and pasting and copying the address,but when I try to enter it via php the image is not shown
$image = wp_get_attachment_image_src( $post_thumbnail_id);
//echo($image[0]);
?>
<img src="<?php $image[0]; ?>" alt="">
The next thing I did was an echo of image[0] and it gave me the url of the image, I copied it and pasted it in the tag and that's when it showed me the image
<img src="mysite/wp-content/uploads/2018/11/957a...150x150.jpg" alt="">
I saw the page in Incognito Window and I did not show the image either.
Any clues?
I have a strange problem, when I try to enter the source of an image tag using PHP it shows me the following error in the inspector
<img src=(unknown) alt="">
this code fragment gives me the correct url, checked by seeing the CPanel and pasting and copying the address,but when I try to enter it via php the image is not shown
$image = wp_get_attachment_image_src( $post_thumbnail_id);
//echo($image[0]);
?>
<img src="<?php $image[0]; ?>" alt="">
The next thing I did was an echo of image[0] and it gave me the url of the image, I copied it and pasted it in the tag and that's when it showed me the image
<img src="mysite/wp-content/uploads/2018/11/957a...150x150.jpg" alt="">
I saw the page in Incognito Window and I did not show the image either.
Any clues?
Share Improve this question asked Nov 21, 2018 at 0:59 TraukoTrauko 251 silver badge6 bronze badges2 Answers
Reset to default 0I think that you need echo the image, try this:
<php
$image = wp_get_attachment_image_src( $post_thumbnail_id );
//echo( $image[0] );
?>
<img src="<?php echo $image[0]; ?>" alt="">
If you only want the URL of the image, use wp_get_attachment_image_url(). It saves you having to do the [0] thing:
<img src="<?php echo wp_get_attachment_image_url( $post_thumbnail_id ); ?>" alt="">
However, if you want to output an image tag for an attachment, you're much better off using wp_get_attachment_image():
echo wp_get_attachment_image( $post_thumbnail_id, 'full' );
This will give you the full <img> tag, but including the alt text, width & height attributes, and srcset attribute. The alt text in particular is important.
本文标签: functionsCant display an image via PHP in wordpress
版权声明:本文标题:functions - Cant display an image via PHP in wordpress 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749164613a2325964.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论