# Keep Custom Field Changes in Revisions

> Saves chosen custom fields, such as a subtitle, price or event date, with every revision so restoring an older version brings those values back too.

- Type: PHP
- Runs: Run everywhere
- Category: [Content](https://wpide.com/library/category/content/)
- Tags: revisions, custom-fields, history
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/content-revisions-keep-custom-fields/

## Code

```php
// Custom field keys to store with revisions.
$wpide_revision_meta_keys = array( 'subtitle', 'price', 'event_date' );

add_filter( 'wp_post_revision_meta_keys', function ( $keys ) use ( $wpide_revision_meta_keys ) {
    return array_values( array_unique( array_merge( $keys, $wpide_revision_meta_keys ) ) );
} );
```

## Notes

Needs WordPress 6.4 or newer; list the field keys in $wpide_revision_meta_keys.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Keep Custom Field Changes in Revisions" 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/
