Site logo

Archived topic

How to add last modified date to bottom of posts?

8 replies · Started by Kevin on May 20, 2017

Viewing posts 1–9 of 9

Hey, quick question here. If I wanted to have this display at the bottom of my posts, how would I do it?

This post was last updated on [date post was last modified].

Hi Kevin,

Would this display on single posts only, or the blog as well?

Let me know :)

Apologies on the slow response! This would be for single posts only, no archive, category, or pages.

Try this in the After Content hook in GP Hooks:

<?php if ( is_single() ) { 
    if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
        $time_string = '<time class="updated" datetime="' . esc_attr( get_the_modified_date( 'c' ) ) . '" itemprop="dateModified">' . esc_html( get_the_modified_date() ) . '</time>';
        echo 'This post was last updated on ' . $time_string;
    }
} ?>

I have Execute PHP checked, btw.

I just edited the code above - can you try again?

All good, Tom. Thanks so much for the help!

You're welcome :)

This archived topic is closed to new replies.