admin管理员组文章数量:1303373
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 badges2 Answers
Reset to default 2Have 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)
本文标签: Getting specific image thumbnail urls of attached images
版权声明:本文标题:Getting specific image thumbnail urls of attached images 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741714246a2394016.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论