最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Getting specific image thumbnail urls of attached images

programmeradmin1浏览0评论

I am using the Manual Image Crop plugin to set thumbnails for images. I am not using any images as 'featured images' however.

I have a number of thumbnails saved to each image. If I use wp_get_attachment_link(id, 'medium'); then I get the desired 'medium' thumbnail returned but as whole html block output, including '' tags, size etc etc.

I just want the URL of this specific thumbnail (or the img tags 'src' attribute). Is there a built in wordpress function for this or will I have to use PHP regex or something?

I am using the Manual Image Crop plugin to set thumbnails for images. I am not using any images as 'featured images' however.

I have a number of thumbnails saved to each image. If I use wp_get_attachment_link(id, 'medium'); then I get the desired 'medium' thumbnail returned but as whole html block output, including '' tags, size etc etc.

I just want the URL of this specific thumbnail (or the img tags 'src' attribute). Is there a built in wordpress function for this or will I have to use PHP regex or something?

Share Improve this question asked Nov 25, 2014 at 12:57 myolmyol 7962 gold badges13 silver badges37 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 2

Have a look at wp_get_attachment_image_src

<?php 
$attachment_id = 8; // attachment ID

$image_attributes = wp_get_attachment_image_src( $attachment_id, 'medium' ); // returns an array
if( $image_attributes ) {
?> 
<img src="<?php echo $image_attributes[0]; ?>" width="<?php echo $image_attributes[1]; ?>" height="<?php echo $image_attributes[2]; ?>">
<?php } ?>

Source: http://codex.wordpress/Function_Reference/wp_get_attachment_image_src#Default_Usage

if you have the $id = 7 for example

and you have $size = ...; choose the size you want

use wp_get_attachment_image_url($id, $size)

发布评论

评论列表(0)

  1. 暂无评论