Title: _delete_attachment_theme_mod
Published: April 25, 2014
Last modified: August 20, 2026

---

# _delete_attachment_theme_mod( int $id )

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/_delete_attachment_theme_mod/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/_delete_attachment_theme_mod/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/functions/_delete_attachment_theme_mod/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/_delete_attachment_theme_mod/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_delete_attachment_theme_mod/?output_format=md#changelog)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Checks an attachment being deleted to see if it’s a header or background image.

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

If true it removes the theme modification which would be pointing at the deleted
attachment.

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

 `$id`intrequired

The attachment ID.

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

    ```php
    function _delete_attachment_theme_mod( $id ) {
    	$attachment_image = wp_get_attachment_url( $id );
    	$header_image     = get_header_image();
    	$background_image = get_background_image();
    	$custom_logo_id   = (int) get_theme_mod( 'custom_logo' );
    	$site_logo_id     = (int) get_option( 'site_logo' );

    	if ( $custom_logo_id && $custom_logo_id === $id ) {
    		remove_theme_mod( 'custom_logo' );
    		remove_theme_mod( 'header_text' );
    	}

    	if ( $site_logo_id && $site_logo_id === $id ) {
    		delete_option( 'site_logo' );
    	}

    	if ( $header_image && $header_image === $attachment_image ) {
    		remove_theme_mod( 'header_image' );
    		remove_theme_mod( 'header_image_data' );
    	}

    	if ( $background_image && $background_image === $attachment_image ) {
    		remove_theme_mod( 'background_image' );
    	}
    }
    ```

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

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

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

Retrieves header image for custom header.

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

Retrieves background image for custom background.

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

Removes theme modification name from active theme list.

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

Retrieves theme modification value for the active theme.

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

Removes an option by name. Prevents removal of protected WordPress options.

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

Retrieves the URL for an attachment.

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

Retrieves an option value based on an option name.

  |

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

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

| Version | Description | 
| [6.6.0](https://developer.wordpress.org/reference/since/6.6.0/) | Also removes `site_logo` option set by the site logo block. | 
| [4.5.0](https://developer.wordpress.org/reference/since/4.5.0/) | Also removes custom logo theme mods. | 
| [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Also removes `header_image_data`. | 
| [3.0.0](https://developer.wordpress.org/reference/since/3.0.0/) | Introduced. |

## User Contributed Notes

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