|
/ Documentation /Developers Documentation/ Preserve Modified Date During Updates surerank_freeze_modified_date

Preserve Modified Date During Updates surerank_freeze_modified_date

Hook: surerank_freeze_modified_date

Description: The surerank_freeze_modified_date filter lets you preserve the existing post_modified and post_modified_gmt values when a post is updated. This is useful for programmatic updates where you want to change post content or metadata without making WordPress treat the post as newly modified.

Source: inc/functions/modified-date-lock.php

Usage: Use this filter when you need to keep the current modified timestamp intact during a post update. SureRank checks this filter only for existing posts, and skips revisions and autosaves.

Example

/**
 * Preserve the modified date for a specific post during updates.
 */
add_filter(
	'surerank_freeze_modified_date',
	function ( $freeze, $post_id ) {
		if ( 123 === (int) $post_id ) {
			return true;
		}

		return $freeze;
	},
	10,
	2
);

Example: Freeze modified dates for updates triggered by a custom process.

/**
 * Preserve modified dates for posts updated by a custom sync routine.
 */
add_filter(
	'surerank_freeze_modified_date',
	function ( $freeze, $post_id, $post, $data, $postarr, $unsanitized_postarr ) {
		if ( ! empty( $unsanitized_postarr['my_custom_sync'] ) ) {
			return true;
		}

		return $freeze;
	},
	10,
	6
);

Arguments:

  • $freeze (bool) Whether to preserve the modified timestamp. Default false.
  • $post_id (int) Post ID being updated.
  • $post (\WP_Post) Current post object from the database before the update.
  • $data (array) Sanitized post data that will be sent to WordPress.
  • $postarr (array) Post data array for the update request.
  • $unsanitized_postarr (array) Original unsanitized post data before WordPress processing.

Notes:

  • This filter only runs during post updates, not new post creation.
  • Revisions and autosaves are ignored.
  • Returning true preserves only post_modified and post_modified_gmt. Other post fields still update normally.
  • Use this only when you intentionally want to avoid changing the visible modified date.

You can add the example code to your child theme’s functions.php file or use a plugin like Code Snippets to safely insert custom code. Using a code snippet plugin is recommended for easier management and to keep the customization active even when changing themes.

Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
Table of Contents
Scroll to Top