# Protect Important Pages From Deletion

> Stops anyone, administrators included, from trashing or deleting the homepage, blog page, privacy page and any other pages you list.

- Type: PHP
- Runs: Run everywhere
- Category: [Admin](https://wpide.com/library/category/admin/)
- Tags: admin, pages, protection
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/protect-key-pages-from-deletion/

## Code

```php
// Extra page or post IDs to protect, besides the homepage, posts page and privacy policy page.
$wpide_protected_ids = array();

add_filter( 'map_meta_cap', function ( $caps, $cap, $user_id, $args ) use ( $wpide_protected_ids ) {
    if ( ! in_array( $cap, array( 'delete_post', 'delete_page' ), true ) || empty( $args[0] ) ) {
        return $caps;
    }

    $protected = array_merge(
        $wpide_protected_ids,
        array(
            (int) get_option( 'page_on_front' ),
            (int) get_option( 'page_for_posts' ),
            (int) get_option( 'wp_page_for_privacy_policy' ),
        )
    );

    if ( in_array( (int) $args[0], array_filter( array_map( 'intval', $protected ) ), true ) ) {
        $caps[] = 'do_not_allow';
    }

    return $caps;
}, 10, 4 );
```

## Notes

To delete a protected page later, change the Reading settings first or deactivate the snippet.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Protect Important Pages From Deletion" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
