Sometimes we may need to display the time when a post was last updated in more human ‘scannable’ way. 6 months ago, 3 days ago, 5 mins ago. It can be quicker to understand than just showing a date.

WordPress has us covered here as there is a function human_time_diff(), which allows us to easily compare two seperate times and then display this in a human readable format.

We can use this function to compare the current time to the time when the post was last modified.

Using the code snippets plugin, let’s create a new function that does exactly this;

function relative_modified_time() {
    $last_modified_time = get_the_modified_time('U');
    $current_time = current_time('U');
    return human_time_diff($last_modified_time,$current_time) . " ago";  

We set this to run on the front end only.

Displaying in Oxygen for Single Posts

Now we have our function, we can use it inside Oxygen. We can add a text element, then select ‘insert data’ at the top of the page.

Next, we select ‘PHP Function Return Value’ and use our new function.

Displaying in Oxygen for Archives

If we wanted to display this data inside Easy Posts for an archive page, we would need to go to the PHP template and echo our function.

<?php echo relative_modified_time(); ?>

All done

Need help implementing a tutorial in your site or want to hire me for custom work?


Find the article helpful and wish to donate?



You need to be logged in to view and post comments.
Not a member yet? Join here.
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram
%d bloggers like this: