您可以使用:
<?php $image_attributes = wp_get_attachment_image_src( $attachment_id, array(1024,1024) ); ?>
<a href="<?php echo $image_attributes[0]; ?>">xxx</a>
请参见
http://codex.wordpress.org/Function_Reference/wp_get_attachment_image_src如果图片太小,将显示原始图片,否则将显示裁剪版本(1024x1024)。
更新:没有正确理解您的问题。以下是您需要的:
首先,为自定义的最大大小添加缩略图大小(true是硬裁剪,false是软比例裁剪)
add_image_size( \'custom_size\', 1024, 1024, true );
然后将其也添加到函数中。php:
function custom_image_media_send_to_editor($html, $attachment_id, $attachment) {
$attachment_ = wp_get_attachment_image_src( $attachment_id, \'custom_size\' );
$attachment[\'url\'] = $attachment_[0];
$post =& get_post($attachment_id);
if ( substr($post->post_mime_type, 0, 5) == \'image\' ) {
$url = $attachment[\'url\'];
$align = !empty($attachment[\'align\']) ? $attachment[\'align\'] : \'none\';
$size = !empty($attachment[\'image-size\']) ? $attachment[\'image-size\'] : \'medium\';
$alt = !empty($attachment[\'image_alt\']) ? $attachment[\'image_alt\'] : \'\';
$rel = ( $url == get_attachment_link($attachment_id) );
return get_image_send_to_editor($attachment_id, $attachment[\'post_excerpt\'], $attachment[\'post_title\'], $align, $url, $rel, $size, $alt);
}
return $html;
}
add_filter(\'media_send_to_editor\', \'custom_image_media_send_to_editor\', 11, 3);
然后,如果图像较大,您将在帖子中添加的下一个图像将获得裁剪版本的URL,或者完整版本是图像较小。