Title: wp_delete_file
Published: April 23, 2015
Last modified: February 24, 2026

---

# wp_delete_file( string $file ): bool

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_delete_file/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_delete_file/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_delete_file/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_delete_file/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_delete_file/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_delete_file/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_delete_file/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_delete_file/?output_format=md#wp--skip-link--target)

Deletes a file.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_delete_file/?output_format=md#parameters)󠁿

 `$file`stringrequired

The path to the file to delete.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_delete_file/?output_format=md#return)󠁿

 bool True on success, false on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_delete_file/?output_format=md#source)󠁿

    ```php
    function wp_delete_file( $file ) {
    	/**
    	 * Filters the path of the file to delete.
    	 *
    	 * @since 2.1.0
    	 *
    	 * @param string $file Path to the file to delete.
    	 */
    	$delete = apply_filters( 'wp_delete_file', $file );

    	if ( ! empty( $delete ) ) {
    		return @unlink( $delete );
    	}

    	return false;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/functions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/functions.php#L7722)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/functions.php#L7722-L7737)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_delete_file/?output_format=md#hooks)󠁿

 [apply_filters( ‘wp_delete_file’, string $file )](https://developer.wordpress.org/reference/hooks/wp_delete_file/)

Filters the path of the file to delete.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_delete_file/?output_format=md#related)󠁿

| Uses | Description | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  |

| Used by | Description | 
| [_wp_before_delete_font_face()](https://developer.wordpress.org/reference/functions/_wp_before_delete_font_face/)`wp-includes/fonts.php` |

Deletes associated font files when a font face is deleted.

  | 
| [wp_delete_file_from_directory()](https://developer.wordpress.org/reference/functions/wp_delete_file_from_directory/)`wp-includes/functions.php` |

Deletes a file if its path is within the given directory.

  | 
| [wp_privacy_generate_personal_data_export_file()](https://developer.wordpress.org/reference/functions/wp_privacy_generate_personal_data_export_file/)`wp-admin/includes/privacy-tools.php` |

Generate the personal data export file.

  | 
| [wp_ajax_crop_image()](https://developer.wordpress.org/reference/functions/wp_ajax_crop_image/)`wp-admin/includes/ajax-actions.php` |

Handles cropping an image via AJAX.

  | 
| [File_Upload_Upgrader::__construct()](https://developer.wordpress.org/reference/classes/file_upload_upgrader/__construct/)`wp-admin/includes/class-file-upload-upgrader.php` |

Construct the upgrader for a form.

  | 
| [wp_restore_image()](https://developer.wordpress.org/reference/functions/wp_restore_image/)`wp-admin/includes/image-edit.php` |

Restores the metadata for a given attachment.

  | 
| [wp_save_image()](https://developer.wordpress.org/reference/functions/wp_save_image/)`wp-admin/includes/image-edit.php` |

Saves image to post, along with enqueued changes in `$_REQUEST['history']`.

  | 
| [Custom_Image_Header::step_3()](https://developer.wordpress.org/reference/classes/custom_image_header/step_3/)`wp-admin/includes/class-custom-image-header.php` |

Displays third step of custom header image page.

  |

[Show 3 more](https://developer.wordpress.org/reference/functions/wp_delete_file/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_delete_file/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_delete_file/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.7.0](https://developer.wordpress.org/reference/since/6.7.0/) | A return value was added. | 
| [4.2.0](https://developer.wordpress.org/reference/since/4.2.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_delete_file/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/wp_delete_file/?output_format=md#comment-content-3805)
 2.   [Mohit Mishra](https://profiles.wordpress.org/mohitmishra/)  [  6 years ago  ](https://developer.wordpress.org/reference/functions/wp_delete_file/#comment-3805)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_delete_file%2F%23comment-3805)
    Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_delete_file%2F%23comment-3805)
 4.     ```php
        $file_path = "/home/public_html/wp-content/uploads/2020/04/photo_img_1-8.png"  // path of the file which need to be deleted.
    
        wp_delete_file( $file_path ); //delete file here.
        ```
    
 5.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_delete_file%2F%3Freplytocom%3D3805%23feedback-editor-3805)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_delete_file%2F)
before being able to contribute a note or feedback.