Gold Penguin Logo with Text

Change Modified Date to Equal Publish Date in WordPress

We'll create a PHP function that returns the more recent date between the modified date of a post and its published date. If the modified date is more recent, the function returns the modified date. Otherwise, it returns the published date.
Updated December 3, 2022

We write tons of content for our agency blog (like this one!). We often write a few articles a day but schedule them out over a week or two. In these cases, the "Publish Date" might be different than the "Modified Date". Initially, the modified date would show the date we wrote the article, but our publish date would be in the future.

The problem is, once we published the article, the modified date would not update and show the current date/time, rather it would show the date we initially wrote it. This can be confusing for our readers, since they might see a post that was published today, but last updated a week ago. This is both incorrect & just looks weird! And let's be honest, we aren't manually going back to edit a post to ensure the modify time is equal to or newer than the publish time. The good news is... we made a simple fix to implement on your WordPress site. All you need to do is add a simple piece of code to your website backend to ensure the post modified date is at least the same date the article was published on.

When writing blogs, tutorials, or other pieces of content, it's often useful to include a "last updated" date. This is helpful for two reasons:

1. It shows your readers that you're keeping the content up-to-date & adjusting content
2. It lets them know how old the information might be.

In this tutorial, we'll safeguard our WordPress blog by making sure the post modified date is at least equal to the content publish date.  If your post modified date is before the publish date we'll display the publishing date to your users. Here's what we mean:

graphic showing post modified date & post publish date, with publish date being the latest update of the article

Calculate Post Modified Date in WordPress

To simply calculate whenever the post was last modified, you can wrap the built in WordPress function to get the modified time. In order to implement this code, you have to download & activate a plugin like Code Snippets. Then, create a new snippet and paste in the code. Save the changes and make sure the snippet is is set to 'run everywhere'.

function gp_last_modified_date( ) {
	return get_the_modified_time('F j, Y');


Display Post Modified Date in Oxygen

Now you'll have to take this code and insert it in the Oxygen Builder. In the styling bar, insert data. Inside scroll down to PHP function return value. For the name, enter the function title (without parenthesis) and leave the arguments field empty.

Display WordPress Post Modified Date Only If Newer than Publish Date

It's fairly simple to get the post modified date in WordPress, but sometimes the modified date is actually before the publish date (in the case of somebody who schedules blogs weeks in advance). If you're scheduling content and want to show the most recent date (whether it's the publish date or the modified date), it takes a little more work:

function gp_display_newer_date() {

	$datePosted = get_the_modified_time('F j, Y');
	$dateUpdated = get_the_date('F j, Y');

	$postedTime = strtotime($datePosted);
	$updatedTime = strtotime($dateUpdated);

	if ($postedTime > $updatedTime) {
		return $datePosted;
		return $dateUpdated;


What this code does is get the modified date and publish date, convert them into seconds since the Unix Epoch, and return the newer of the two dates. If your post was scheduled, it will display the latest date of the two. If you edit and make changes to a published post, it will show the date those changes were made. You can implement this function just as before, but make sure to update the function name.

If you'd like to paste this into your site with any html/php element go ahead and add the following code (remember the previous function must be activated)


echo 'The most recent date for this post is: ' . gp_display_newer_date();



Scheduling content is a great way to plan ahead, but if you want to make sure your post modified date is at least equal to your post publish date you would have to implement this function.

We hope this tutorial helped you learn how to show the most recent post modified date in Oxygen Builder (or any WordPress website for that matter!). If you have any questions or suggestions, please let us know in the comments below. Hope this helped!

Want To Learn Even More?
If you enjoyed this article, subscribe to our free monthly newsletter
where we share tips & tricks on how to use tech & AI to grow and optimize your business, career, and life.
Written by Justin Gluska
Justin is the founder of Gold Penguin, a business technology blog that helps people start, grow, and scale their business using AI. The world is changing and he believes it's best to make use of the new technology that is starting to change the world. If it can help you make more money or save you time, he'll write about it!
Notify of

Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Join Our Newsletter!
If you enjoyed this article, subscribe to our newsletter where we share tips & tricks on how to make use of some incredible AI tools that you can use to grow and optimize a business