当前位置:网站首页>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 .
边栏推荐
- MySQL index and its classification
- [tcapulusdb knowledge base] Introduction to tcapulusdb tcapsvrmgr tool (III)
- Cool in summer
- Interviewer: do you understand redis' shared object pool?
- What is low code for digital Nova? What is no code
- Pycharm in Chinese
- How to use 200 lines of code to implement Scala's Object Converter
- 隐私计算FATE-离线预测
- MySQL locking mechanism and four isolation levels
- Details of istio micro service governance grid traffic management core resource controller
猜你喜欢

IJCAI 2022 | greatly improve the effect of zero sample learning method with one line of code. Nanjing Institute of Technology & Oxford proposed the plug and play classifier module

zabbix支持钉钉报警

Quick news: Huawei launched the Hongmeng developer competition; Tencent conference released the "Wanshi Ruyi" plan

Cesium realizes satellite orbit detour

Bluetooth health management device based on stm32

AGCO AI frontier promotion (6.27)

爱可可AI前沿推介(6.27)

基于SSM实现招聘网站

Size end byte order

Record number of visits yesterday
随机推荐
Prometheus 2.26.0 new features
如何使用200行代码实现Scala的对象转换器
基于SSM实现招聘网站
深信服X计划-系统基础总结
Read a poem
【Acwing】第57场周赛 题解
外包2年的我终于上岸了!记录我的字节跳动3轮面试,希望帮助到大家!
Record number of visits yesterday
dynamic programming
Different habits
Journal quotidien des questions (6)
Pre training weekly issue 51: reconstruction pre training, zero sample automatic fine tuning, one click call opt
Nifi from introduction to practice (nanny level tutorial) - identity authentication
Explore tidb lightning source code to solve the found bugs
OpenHGNN发布0.3版本
内网学习笔记(8)
crane:字典项与关联数据处理的新思路
Principle of printf indefinite length parameter
一道shell脚本的统计题
快速搭建一个自己的访问国外网站,搭建ss并开启bbr快速上网