Filters the path of the file to delete.
Parameters
$filestring- Path to the file to delete.
Source
$delete = apply_filters( 'wp_delete_file', $file );
Changelog
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |
Filters the path of the file to delete.
$filestring$delete = apply_filters( 'wp_delete_file', $file );
| Version | Description |
|---|---|
| 2.1.0 | Introduced. |
You must log in before being able to contribute a note or feedback.
Here’s a quick one-liner using this filter that I wrote for a site that serves .webp images as well as whatever jpeg or png was uploaded to WordPress. When any image file is deleted, it also deletes the .webp version, if it exists. e.g. when you delete an image such as
/uploads/2024/01/example.pngfrom the Media Library, it will also delete/uploads/2024/01/example.webp.