Change Modified Date to Equal Publish Date in WordPress

Published by Justin on August 9, 2022
Last Updated: October 4, 2022 | Reading Time: 3 minutes

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.

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.

✏️

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

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

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

}

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'.

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 Post Modified If Newer than Publish Date in Oxygen

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;
	}
	else{
		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.

Conclusion

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!

Written by Justin
Justin is the founder of Gold Penguin, a web design and marketing agency that helps businesses achieve their online goals. Justin has a passion for web design and marketing, and he loves working with clients to help them grow their businesses.

Comments

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
Made with 💛 by Gold Penguin © 2022