为此,钩住wp\\u get\\u attachment\\u链接。下面是一个如何操作的示例-
function attachment_link_filter( $content, $post_id, $size, $permalink ) {
// Only do this if we\'re getting the file URL
if (! $permalink) {
// This returns an array of (url, width, height)
$image = wp_get_attachment_image_src( $post_id, \'large\' );
$new_content = preg_replace(\'/href=\\\'(.*?)\\\'/\', \'href=\\\'\' . $image[0] . \'\\\'\', $content );
return $new_content;
} else {
return $content;
}
}
add_filter(\'wp_get_attachment_link\', \'attachment_link_filter\', 10, 4);