Some websites regularly update their publications when adding new material. In this case it would be much more convenient to display under the post not the original publication date, but the date of the last modification, so that the user would understand how relevant the information is.

In this little lesson, we show how you can display the date of the last modification of your entries on WordPress . Let’s get going!

When should I show the date of the last update?

Most WordPress themes display the publication date of a post. This is a standard feature that is suitable for all blogs.

However, WordPress is also often used on projects where old publications can often be updated or supplemented with new content. This is typical for sites with news. When new updated information appears, they are added to the already published material. And in this case it is much more useful to show the date of the last change of such publication.

Let’s see how you can display the date of the last change to the post on WordPress.

Method 1. Showing the date of the last change before the content of the recording

To display the date of the last change of the post before the beginning of the text, copy and paste this code into your functions.php current skin file:

function wpb_last_updated_date ($ content) 
$ U_time = get_the_time ('U');
$ U_modified_time = get_the_modified_time ('U');
If ($ u_modified_time> = $ u_time + 86400)
$ Updated_date = get_the_modified_time ('F jS, Y');
$ Updated_time = get_the_modified_time ('h: i a');
$ Custom_content. = '

Last updated on’. $ Updated_date. ‘At’. $ Updated_time. ‘

‘; $ Custom_content. = $ Content; Return $ custom_content; Add_filter (‘the_content’, ‘wpb_last_updated_date’);

This code checks and compares 2 dates: the publication date and the last modification date. If these dates do not match, then the code displays the date of the last change before the start of the recording content.

You can add your CSS to change the appearance for the date output. Here is an example that you can use:

.last-updated 
Font-size: small;
Text-transform: uppercase;
Background-color: # fffdd4;

And this is how it will look on your website:

Method 2. Date of last modification in theme templates

This method is more complex, since you will need to edit specific skin templates that are responsible for displaying your posts.

The problem is that now many modern WordPress themes use their individual template tags, which are responsible for displaying meta-data of the record, including the date and time of publication.

The file single.php and archive.php responds in simpler topics to the output of records, and the code that displays the recording date will be in the same files

So first you have to figure out and find out exactly which file contains the code that we want to change in order to display the date of the last change. If you are lucky, it will be single.php.

In our demo version, we found the output date output code and immediately below it we added our code to output the date of the last change. Here’s the code:

$ u_time = get_the_time ('U');
$ U_modified_time = get_the_modified_time ('U');
If ($ u_modified_time> = $ u_time + 86400)
Echo "

Last modified on”; The_modified_time (‘F jS, Y’); Echo “at”; The_modified_time (); Echo “

“;

Here’s how it looks on the site:

Results

In this lesson we showed 2 ways how to display the date of the last record change to WordPress:

  • Add code to functions.php to display the date of the last change before the start of the recording content
  • Find and change the code in the skin templates to change the standard publication publication date.
One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.