网站优化

网站优化

Products

当前位置:首页 > 网站优化 >

从WordPress内容中删除文件名的宽度和高度

GG网络技术分享 2025-03-18 16:12 4


问题描述:

When you upload an image in WordPress, it usually displays one of the smaller size versions of it in the format imagename-123x456.jpg, where 123x456 is the WIDTHxHEIGHT. I want to filter the content and remove -123x456 from the end of all filenames so that it instead displays the original high resolution images.

I\'m thinking something like this:

function replace_content($content) {

$content = str_replace(\'-123x456.jpg\', \'.jpg\', $content);

return $content;

}

add_filter(\'the_content\',\'replace_content\');

But obviously it needs to be more versatile to replace all possible sizes.

P.S. I don\'t want to have to set the size of the image in the post editor..

图片转代码服务由CSDN问答提供

感谢您的意见,我们尽快改进~

功能建议

在WordPress中上传图像时,它通常以imagename-格式显示其中一个较小尺寸的版本 123x456.jpg,其中123x456是WIDTHxHEIGHT。 我想过滤内容并从所有文件名的末尾删除-123x456,以便它显示原始的高分辨率图像。 </ p>

我在想这样的事情:</ p>

  function replace_content($ content){

$ content = str_replace(\' - 123x456 .jpg\',\'.jpg\',$ content);

返回$ content;

}

add_filter(\'the_content\',\'replace_content\');

</ code> </ pre>

但显然需要更多才能更换所有可能的尺寸。</ p>

PS 我不想在帖子编辑器中设置图像的大小.. </ p>

</ div>

网友观点:

To remove from all the images the size in the_content() and support different images extensions you need to use preg_replace like this.

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\');

标签:

提交需求或反馈

Demand feedback