WordPress建站教程:如何通过图片重命名优化SEO效果
作者:悦然WordPress建站 | Author: YueRan WordPress Website Building
在WordPress建站过程中,图片优化是SEO不可忽视的重要环节。今天我们将重点讲解一个关键细节——图片文件名的优化处理。
In WordPress website building, image optimization is a crucial aspect of SEO. Today we'll focus on a key detail - optimizing image filenames.
问题背景:默认情况下,WordPress上传的图片会保留原始文件名。中文用户习惯使用中文命名图片,这会导致URL中出现中文字符,不利于搜索引擎抓取。
Background: By default, WordPress keeps original filenames when uploading images. Chinese users tend to use Chinese characters in filenames, which creates URLs with Chinese characters that are not SEO-friendly.
解决方案一:使用插件
Solution 1: Using Plugins
推荐两款实用插件:
Recommended plugins:
- Unique Rename Image File Upload - 自动重命名上传图片
- Enable Media Replace - 可批量重命名现有图片
解决方案二:添加代码
Solution 2: Adding Code
将以下代码添加到functions.php文件:
Add this code to functions.php:
add_filter('wp_handle_upload_prefilter', 'custom_upload_filter' ); function custom_upload_filter( $file ){ $info = pathinfo($file['name']); $ext = $info['extension']; $filedate = date('YmdHis').rand(10,99); $file['name'] = $filedate.'.'.$ext; return $file; } 解决方案三:使用自带功能的主题
Solution 3: Using Themes with Built-in Feature
部分优质WordPress主题已集成图片重命名功能。
Some premium WordPress themes already include image renaming feature.
SEO优化建议:图片重命名虽是小细节,但对SEO有积极影响。建议使用英文或数字命名图片文件。
SEO Tip: Although image renaming seems minor, it positively impacts SEO. We recommend using English or numbers for image filenames.