您可以使用the_content
filter可过滤所有帖子内容并替换img源。
add_filter( \'the_content\', \'show_full_sized_images\' );
/**
* Replaces all -600x999 images with full image url
* @param string $content
* @return string
*/
function show_full_sized_images( $content ) {
$pattern = \'~(http[^\\\'"]*)(-600x[0-9]{2,4})(\\.jpe?g|png|gif)~i\';
$m = preg_match_all( $pattern, $content, $matches );
echo \'<pre>\' . esc_html( print_r( $matches, 1 ) ) . \'</pre>\';
return preg_replace( $pattern, \'$1$3\', $content );
}
您还需要添加以下css,因为宽度可能受到
width
中的属性
img
标签:
img {
width: auto;
height: auto;
}