[Resolved] Need article updated date and time in the following format

Home Forums Support [Resolved] Need article updated date and time in the following format

Home Forums Support Need article updated date and time in the following format

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1660814
    Haider Ali

    Hello,

    I got the article updated date shown on all articles using the following code:
    add_filter( 'generate_post_date_show_updated_only', '__return_true' );

    However, I would like my articles to show the time and date of it last being updated.
    Example: February 17, 2021 1:35 pm UTC

    For your information, UTC is the timezone.

    On my previous theme, I had got it done by the following code:

    function astra_add_time_with_date( $format ) {
        $format = 'F j, Y g:i a T' ;
        return $format;
    }

    Thank you

    #1661200
    Elvin
    Staff
    Customer Support

    Hi there,

    You can actually use the same F j, Y g:i a T format on Dasboard > Setting > General date format as shown here: https://share.getcloudapp.com/7KupojLk

    Alternatively, you can filter the post date output using generate_post_date_output filter:

    Example:

    add_filter( 'generate_post_date_output', function() {
    	$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s %5$s</time> ';
    
    	if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
    		$time_string = '<time class="updated" datetime="%3$s" itemprop="dateModified">%4$s %6$s</time> ' . $time_string;
    	}
    
    	$time_string = sprintf( $time_string,
    		esc_attr( get_the_date( 'c' ) ),
    		esc_html( get_the_date( 'F j, Y' ) ),
    		esc_attr( get_the_modified_date( 'c' ) ),
    		esc_html( get_the_modified_date( 'F j, Y' ) ),
    		esc_html( get_the_date( 'g:i A T' ) ),
    		esc_html( get_the_modified_date( 'g:i A T' ) )
    	);
    
    	return sprintf( '<span class="posted-on">%1$s</span>', // WPCS: XSS ok, sanitization ok.
    		sprintf( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>',
    			esc_url( get_permalink() ),
    			esc_attr( get_the_time() ),
    			$time_string
    		)
    	);
    } );

    A wise man once said:
    "Have you cleared your cache?"

    #1661239
    Haider Ali

    Thank you Elvin.

    The code you provided got the date and time displayed just like I wanted. 😊

    Cheers!

    #1661248
    Elvin
    Staff
    Customer Support

    No problem. Glad to be of any help. πŸ˜€

    A wise man once said:
    "Have you cleared your cache?"

    #1663649
    Haider Ali

    Hello Elvin,

    I just updated an old article and noticed that the date and time displayed is the publishing date and not the modified date/time. Could you please help with this?

    Thank you πŸ˜„

    #1663663
    Ying
    Staff
    Customer Support

    Hi Haider,

    Have you tried clear cache and disable cache plugin see if that works?
    If not, could you link us to the post in question, you could use the private info field.
    Thanks!

    #1663667
    Haider Ali

    Hello Ying,

    Yes, I have cleared cache, disabled cache plugins and still didn’t see the article updated date/time.

    I see the same old article date/time.

    Link as has been shared in private information.

    Thank you

    #1663681
    Ying
    Staff
    Customer Support

    The updated date has been generated correctly, it’s this display: none;CSS is preventing it from showing πŸ™‚

    #1663706
    Haider Ali

    Got it, thank you so much Ying!

    Cheers!

    #1663709
    Ying
    Staff
    Customer Support

    You are welcome πŸ™‚

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.