---
title: "Code xóa dấu tên file khi upload lên wordpress"
description: "Ngày nay rất nhiều bạn đặt tên ảnh / file thường kèm dấu tiếng Việt, để dễ nhớ, dễ đọc. Tuy nhiên, khi đưa lên website, việc tên ảnh có dấu sẽ có vài điểm bất"
featured_image: "https://legiang360.com/wp-content/uploads/2024/01/Le-Giang-Web-Produces-cleaner-filenames-for-uploads.jpg"
url: "https://legiang360.com/code-xoa-dau-ten-file-khi-upload-len-wordpress/"
date_modified: "2025-06-07T11:50:43+07:00"
---

# Code xóa dấu tên file khi upload lên wordpress

![Lê giang web produces cleaner filenames for uploads](https://legiang360.com/wp-content/uploads/2024/01/Le-Giang-Web-Produces-cleaner-filenames-for-uploads.jpg)

# Code xóa dấu tên file khi upload lên wordpress

- [sieunhim](https://legiang360.com/author/sieunhim/)
- 27.01.2024
- [Wordpress](https://legiang360.com/category/wordpress/)

Ngày nay rất nhiều bạn đặt tên ảnh / file thường kèm dấu tiếng Việt, để dễ nhớ, dễ đọc. Tuy nhiên, khi đưa lên website, việc tên ảnh có dấu sẽ có vài điểm bất lợi

- URL ảnh có dấu, không tốt cho SEO
- Tên ảnh có dấu, không tối ưu cho việc tìm kiếm trên wordpress
- Có thể gây lỗi mất ảnh khi tiến hành backup, di chuyển website giữa các hosting/vps

Để khắc phục việc này, mình xin chia sẻ code xử lý cái dấu này tự động khi bạn upload ảnh/file lên wordpress.

Bạn up code này vào functions.php của theme đang dùng nhé

```
/**
 * Produces cleaner filenames for uploads
 */
function ttv_sanitize_file_name( $filename ) {
    $sanitized_filename = remove_accents( $filename ); // Convert to ASCII
    // Standard replacements
    $invalid = array(
        ' '   => '-',
        '%20' => '-',
        '_'   => '-',
    );
    $sanitized_filename = str_replace( array_keys( $invalid ), array_values( $invalid ), $sanitized_filename );
    $sanitized_filename = preg_replace('/[^A-Za-z0-9-\. ]/', '', $sanitized_filename); // Remove all non-alphanumeric except .
    $sanitized_filename = preg_replace('/\.(?=.*\.)/', '', $sanitized_filename); // Remove all but last .
    $sanitized_filename = preg_replace('/-+/', '-', $sanitized_filename); // Replace any more than one - in a row
    $sanitized_filename = str_replace('-.', '.', $sanitized_filename); // Remove last - if at the end
    $sanitized_filename = strtolower( $sanitized_filename ); // Lowercase
    return $sanitized_filename;
}
add_filter( 'sanitize_file_name', 'ttv_sanitize_file_name', 10, 1 );
```

Lưu ý: Đây là xử lý tự động khi bạn sắp up lên, còn những ảnh/file đã up lên thì chúng ta cần tìm tool khác nhé.

Chúc các bạn seo tốt!

4.7/5 - (8 bình chọn)

#### Bài viết liên quan

[!\[Website security guide\](https://legiang360.com/wp-content/uploads/2026/01/website-security-guide-768x432.webp)](https://legiang360.com/4-lop-bao-mat-thiet-yeu-cho-website-wordpress/)

#### [4 Lớp Bảo Mật Thiết Yếu Cho Website WordPress](https://legiang360.com/4-lop-bao-mat-thiet-yeu-cho-website-wordpress/)

[!\[Plugin qa\](https://legiang360.com/wp-content/uploads/2026/01/plugin-qa-768x768.jpg)](https://legiang360.com/plugin-isures-qrcode-payment-for-vietnam-plugin68-com/)

#### [Plugin iSures QrCode Payment for Vietnam – Plugin68.com](https://legiang360.com/plugin-isures-qrcode-payment-for-vietnam-plugin68-com/)

[!\[Image\](https://legiang360.com/wp-content/uploads/2025/10/image-768x249.png)](https://legiang360.com/yctvn-media-offload-for-cloudflare-r2/)

#### [Yctvn Media Offload for Cloudflare R2](https://legiang360.com/yctvn-media-offload-for-cloudflare-r2/)

[!\[Screenshot 1\](https://legiang360.com/wp-content/uploads/2025/09/screenshot-1-768x329.png)](https://legiang360.com/speedycache-bo-nho-dem-toi-uu-hoa-hieu-suat/)

#### [SpeedyCache – Bộ nhớ đệm, Tối ưu hóa, Hiệu suất](https://legiang360.com/speedycache-bo-nho-dem-toi-uu-hoa-hieu-suat/)

[!\[Bao mat website 1\](https://legiang360.com/wp-content/uploads/2025/09/bao-mat-website-1-768x432.webp)](https://legiang360.com/huong-dan-tang-cuong-bao-mat-wordpress-cho-nguoi-moi-bat-dau/)

#### [Hướng dẫn tăng cường bảo mật WordPress cho người mới bắt đầu](https://legiang360.com/huong-dan-tang-cuong-bao-mat-wordpress-cho-nguoi-moi-bat-dau/)

[!\[Su dung plugin index wp mysql de tang toc website wordpress 001\](https://legiang360.com/wp-content/uploads/2025/06/su-dung-plugin-index-wp-mysql-de-tang-toc-website-wordpress-001-768x404.jpg)](https://legiang360.com/tang-toc-website-wordpress-voi-plugin-index-wp-mysql/)

#### [Tăng tốc website wordpress với plugin Index WP MySQL](https://legiang360.com/tang-toc-website-wordpress-voi-plugin-index-wp-mysql/)

![](https://legiang360.com/wp-content/uploads/2026/05/photo_2026-05-27_01-59-38-630x630.jpg)
