简体   繁体   中英

How to add href around echo image in php?

我正在尝试在下面的 x 图像周围添加永久链接()或简单的“href”链接。

echo '<img src="' . $image_src[0]  . '" width="100%" class="blog-image-border" />';
echo '<a href="'.the_permalink().'"><img src="' . $image_src[0]  . '" width="100%" class="blog-image-border" /></a>';

Try below code for. image take link of post or page in while loop.

if you want to get page/post url for image then use below code.

echo '<a href="'.get_the_permalink().'"><img src="' . $image_src[0]  . '" width="100%" class="blog-image-border" /></a>';

if you want to get current image url then use below code.

echo '<a href="'.esc_url_raw( $image_src[0] ).'"><img src="' . esc_url_raw( $image_src[0] )  . '" width="100%" class="blog-image-border" /></a>';

This code is tested and working perfect to wrap link of image

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