25% off ProSNIPC25OFF

Show Both Published and Modified Dates

Appends both the original publish date and the last-modified date below single-post content.

PHPby SnipCraft
php
<?php
add_filter( 'the_content', 'scseed_show_pub_mod_dates', 20 );
function scseed_show_pub_mod_dates( $content ) {
    if ( ! is_singular( 'post' ) || is_admin() ) {
        return $content;
    }
    $fmt       = get_option( 'date_format' );
    $published = get_the_date( $fmt );
    $modified  = get_the_modified_date( $fmt );
    $html  = '<p class="scseed-post-dates" style="font-size:.875em;color:#666;margin-top:1.5em;">';
    $html .= '<span>' . esc_html__( 'Published:', 'scseed' ) . ' ';
    $html .= '<time datetime="' . esc_attr( get_the_date( 'c' ) ) . '">' . esc_html( $published ) . '</time></span>';
    if ( $modified !== $published ) {
        $html .= ' &mdash; <span>' . esc_html__( 'Last updated:', 'scseed' ) . ' ';
        $html .= '<time datetime="' . esc_attr( get_the_modified_date( 'c' ) ) . '">' . esc_html( $modified ) . '</time></span>';
    }
    $html .= '</p>';
    return $content . $html;
}
#content#dates#display#modified#post