wordpress 禁止自动裁剪缩略图功能

在WordPress中,如果你想要取消自动裁剪(auto-cropping)功能,你可以通过编写一个插件或直接在主题的functions.php文件中添加代码来实现。

以下是一个简单的代码示例,演示如何通过一个插件来禁用WordPress的自动裁剪功能:

<?php
/*
Plugin Name: Disable Auto-Cropping
Plugin URI: https://yourwebsite.com/disable-auto-cropping/
Description: Disables WordPress's auto-cropping feature.
Author: Your Name
Version: 1.0
License: GPL2
*/
 
add_filter('wp_image_editors', function($editors){
    return array();
});
 
add_filter('image_resize_dimensions', function($default, $orig_w, $orig_h, $dest_w, $dest_h, $crop){
    if($crop){
        return array($orig_w, $orig_h, false); // Return the original dimensions and set $crop to false
    }
    return array($dest_w, $dest_h, $crop);
}, 10, 6);
?>

将上述代码保存为一个PHP文件,然后将文件上传到你的WordPress插件目录。之后,在你的WordPress插件页面激活这个插件,它将取消自动裁剪功能。如果你想要将代码直接添加到主题的functions.php文件中,只需确保将代码放在该文件的适当位置。

原创文章,作者:霍欣标,如若转载,请注明出处:https://www.yijing21.cn/seo/242.html

(0)
霍欣标的头像霍欣标
上一篇 2023 年 12 月 2 日 23:35
下一篇 2天前

相关推荐