当您在WordPress上传图像时,它通常以imagename-123x456.jpg格式显示其中一个较小尺寸的版本,其中123x456是WIDTHxHEIGHT。我想过滤内容并从所有文件名的末尾删除-123x456,以便它显示原始的高分辨率图像。
我在想这样的事情:
function replace_content($content) {
$content = str_replace('-123x456.jpg', '.jpg', $content);
return $content;
}
add_filter('the_content','replace_content');
但显然需要更多才能更换所有可能的尺寸。
P.S。我不想在帖子编辑器中设置图像的大小..
答案 0 :(得分:1)
要从the_content()
中移除所有图片并支持不同的图片扩展程序,您需要使用preg_replace。
function replace_content($content) {
$content = preg_replace('/-([^-]*(\d+)x(\d+)\.((?:png|jpeg|jpg|gif|bmp)))"/', '.${4}"', $content);
return $content;
}
add_filter('the_content','replace_content');