【问题标题】:WordPress: How to rename image during upload with current date?WordPress:如何在上传时使用当前日期重命名图像?
【发布时间】:2021-04-02 02:02:09
【问题描述】:

有没有插件可以在上传到wordpress库的时候加上当前日期和文件名?

Example:

Normal   : example_image.jpg
Sanitized: 23_12_2020-example_image.jpg

是否可以在 WordPress 上做到这一点,请帮助!

【问题讨论】:

    标签: php wordpress wordpress-theming regexp-replace


    【解决方案1】:
    function image_name_with_date($filename) {
        $info = pathinfo($filename);
        $ext  = empty($info['extension']) ? '' : '.' . $info['extension'];
        /* check image is file or not */
        if ($info['extension']== 'jpg' || $info['extension'] == 'jpeg' || 
       $info['extension'] == 'gif' || $info['extension'] == 'png') {
           $name = basename($filename, $ext);
            return date('d_m_y').'-'.$name.$ext;                                                      
        } 
     return $filename; //if file is not image
    }                                                                   
    add_filter('sanitize_file_name', 'image_name_with_date, 10);
    

    【讨论】:

    • 很高兴解决您的问题。如果您有问题,请随时问我。谢谢
    猜你喜欢
    • 2015-02-24
    • 1970-01-01
    • 1970-01-01
    • 2017-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多