当前位置:网站首页>A method to realize automatic renaming of pictures uploaded by WordPress
A method to realize automatic renaming of pictures uploaded by WordPress
2022-06-27 13:32:00 【Your mingmingna】
When we use WordPress When you post , Often you need to add pictures 、 Multimedia or something .
However , Everybody knows WordPress It's an import , For Chinese users , We all name the pictures in Chinese , because WordPress The reason for the mechanism , It doesn't normally display pictures or various problems .
that , How to make WordPress The picture is automatically renamed and displayed normally ?
Now? , Let's talk about something more grounded WordPress skill , When we upload pictures , It can automatically change the name of the picture into English or numbers .
Specifically, it is named according to the upload time and MD5 The transcoding file name is 32 Two file naming methods of bit string , You can only choose one .
One 、 Name according to the upload time
function custom_upload_filter( $file ){
$info = pathinfo($file['name']);
$ext = $info['extension'];
$filedate = date('YmdHis').rand(10,99);// To avoid repetition of time , Add another paragraph 2 Random number of bits
$file['name'] = $filedate.'.'.$ext;
return $file;
}
add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' );Two 、 file name md5 Transcode as 32 A string
function custom_upload_filter( $file ){
$info = pathinfo($file['name']);
$ext = '.' . $info['extension'];
$md5 = md5($file['name']);
$file['name'] = $md5.$ext;
return $file;
}
add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' );Edible method
Add code to the... Of the topic you are using functions.php In the file .
The above two methods are implemented WordPress You can only choose one of two ways to upload an image and rename it automatically , Do not use both methods at the same time , Otherwise, if you make mistakes, you will bear the consequences .
边栏推荐
- ThreadLocal 源码全详解(ThreadLocalMap)
- Today's sleep quality record 78 points
- Interviewer: do you understand redis' shared object pool?
- Hardware development notes (VII): basic process of hardware development, making a USB to RS232 module (VI): creating 0603 package and associating principle graphic devices
- MySQL 索引及其分类
- Shell 简明教程
- Local visualization tool connects to redis of Alibaba cloud CentOS server
- JVM parameter setting and analysis
- Infiltration learning diary day20
- Cloud native (30) | kubernetes' app store Helm
猜你喜欢

Pre training weekly issue 51: reconstruction pre training, zero sample automatic fine tuning, one click call opt

Teach you how to build a permanent personal server!

zabbix支持钉钉报警

Cool in summer

Implementation of recruitment website based on SSM

Hardware development notes (VII): basic process of hardware development, making a USB to RS232 module (VI): creating 0603 package and associating principle graphic devices

Journal quotidien des questions (6)

今日睡眠质量记录78分

Size end byte order

Embedded development: embedded foundation callback function
随机推荐
Embedded development: embedded foundation callback function
同花顺能开户炒股吗?安全吗?
今天运气不错
How to choose LAN instant messaging software
嵌入式开发:嵌入式基础——回调函数
Hue new account error reporting solution
再懂已是曲中人
打印输出数(递归方法解决)
每日刷题记录 (六)
MySQL index and its classification
What is low code for digital Nova? What is no code
实现WordPress上传图片自动重命名的方法
【动态规划】—— 背包问题
防火墙基础之华为华三防火墙web页面登录
基于STM32设计的蓝牙健康管理设备
Make learning pointer easier (2)
[acwing] explanation of the 57th weekly competition
crane:字典项与关联数据处理的新思路
爱可可AI前沿推介(6.27)
Failed to execute NPM instruction, prompting ssh: Permission denied