Title: Custom_Image_Header::ajax_header_remove
Published: April 25, 2014
Last modified: February 24, 2026

---

# Custom_Image_Header::ajax_header_remove()

## In this article

 * [Description](https://developer.wordpress.org/reference/classes/custom_image_header/ajax_header_remove/?output_format=md#description)
 * [Source](https://developer.wordpress.org/reference/classes/custom_image_header/ajax_header_remove/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/custom_image_header/ajax_header_remove/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/custom_image_header/ajax_header_remove/?output_format=md#changelog)

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

Given an attachment ID for a header image, unsets it as a user-uploaded header image
for the active theme.

## 󠀁[Description](https://developer.wordpress.org/reference/classes/custom_image_header/ajax_header_remove/?output_format=md#description)󠁿

Triggered when the user clicks the overlay “X” button next to each image choice 
in the Customizer’s Header tool.

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

    ```php
    public function ajax_header_remove() {
    	check_ajax_referer( 'header-remove', 'nonce' );

    	if ( ! current_user_can( 'edit_theme_options' ) ) {
    		wp_send_json_error();
    	}

    	$attachment_id = absint( $_POST['attachment_id'] );
    	if ( $attachment_id < 1 ) {
    		wp_send_json_error();
    	}

    	$key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();
    	delete_post_meta( $attachment_id, $key );
    	delete_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_stylesheet() );

    	wp_send_json_success();
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-admin/includes/class-custom-image-header.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/class-custom-image-header.php#L1484)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/class-custom-image-header.php#L1484-L1501)

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

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

Retrieves name of the current stylesheet.

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

Deletes a post meta field for the given post ID.

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

Returns whether the current user has the specified capability.

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

Verifies the Ajax request to prevent processing requests external of the blog.

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

Sends a JSON response back to an Ajax request, indicating failure.

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

Converts a value to non-negative integer.

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

Sends a JSON response back to an Ajax request, indicating success.

  |

[Show 5 more](https://developer.wordpress.org/reference/classes/custom_image_header/ajax_header_remove/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/custom_image_header/ajax_header_remove/?output_format=md#)

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

| Version | Description | 
| [3.9.0](https://developer.wordpress.org/reference/since/3.9.0/) | Introduced. |

## User Contributed Notes

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