Archived topic
How to show last modified instead of created date?
7 replies · Started by Chandan on December 23, 2016
Hello,
I would like to show last modified date on single post & category instead of post creation date. How can I do this?
I managed to find this in forum but need some tweaking.
Currently, it shows as "Last updated: $date by author"
However, I would like to show as "By Chandan Kumar | Last Updated: $date
Just change your time zone
<p>By <?php the_author_meta('user_firstname'); ?> <?php the_author_meta('user_lastname'); ?> | Last updated <?php date_default_timezone_set('Australia/Perth'); echo human_time_diff(get_the_modified_date('U'), current_time('timestamp')) . ' ago'; ?></p>
Which function are you using? Can you link me to it?
Hello Tom,
I tried this - https://gist.github.com/generatepress/57ef8336f9afec9bb42a
I see above function shows Hyperlink to date & Author. All I want to print like below.
“By $author | Last Updated: $date
Author or date shouldn't have any hyperlink. Please let me know what all I need to.
1. Take the date and place it after the author block:
https://gist.github.com/generatepress/57ef8336f9afec9bb42a#file-template-tags-php-L21-L30
https://gist.github.com/generatepress/57ef8336f9afec9bb42a#file-template-tags-php-L43
2. Replace "by" with "By": https://gist.github.com/generatepress/57ef8336f9afec9bb42a#file-template-tags-php-L36
3. Replace this line: https://gist.github.com/generatepress/57ef8336f9afec9bb42a#file-template-tags-php-L23
With: printf( '<span class="posted-on">| Last Updated: %1$s</span>',
Date is not showing. Here is my code.
`if ( ! function_exists( 'generate_posted_on' ) ) :
/**
* Prints HTML with meta information for the current post-date/time and author.
*/
function generate_posted_on()
{
$date = apply_filters( 'generate_post_date', true );
$author = apply_filters( 'generate_post_author', true );
//$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) )
$time_string .= '<time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time>';
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
// If our author is enabled, show it
if ( $author ) :
printf( ' <span class="byline">%1$s</span>',
sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%1$s <span class="author-name" itemprop="name">%4$s</span></span>',
__( 'by','generatepress'),
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
esc_html( get_the_author() )
)
);
endif;
// If our date is enabled, show it
if ( $date ) :
printf( '<span class="posted-on">| Last Updated: %1$s</span>',
sprintf( '%3$s',
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
$time_string
)
);
endif;
}
endif;
Ah, the code you'r using removes the date in favor of the updated date.
Remove the two forward slashes (//) on this line: https://gist.github.com/generatepress/57ef8336f9afec9bb42a#file-template-tags-php-L10