Site logo

Archived topic

How To Show Time On Post

4 replies · Started by Kenneth on November 27, 2016

Viewing posts 1–5 of 5

I have searched the forums but could not find an answer. I already have date published and date modified showing up for my post, how can I add time to that? I would like to add the physical time (example 3:00pm) and the moments ago time for when a post is updated.

Thanks for your time.

It is showing the time and dates for both, but not showing the "moments ago" time as well. Also how could I get the original published date to say Published before the date?

I have no idea if this will work to switch the time to "moments ago" etc.. but it's worth a shot:

add_filter( 'get_the_date', 'tu_convert_to_time_ago' ), 10, 1 );
add_filter( 'the_date', 'tu_convert_to_time_ago' ), 10, 1 );
add_filter( 'get_the_time', 'tu_convert_to_time_ago' ), 10, 1 );
add_filter( 'the_time', 'tu_convert_to_time_ago' ), 10, 1 );
function tu_convert_to_time_ago( $orig_time ) {
	global $post;
	$orig_time = strtotime( $post->post_date ); 
	return human_time_diff( $orig_time, current_time( 'timestamp' ) ).' '.__( 'ago' );
}

To add "Published", find:

%2$s <span class="time">at %6$s</span>

And replace it with:

Published: %2$s <span class="time">at %6$s</span>

Hi Kenneth,

After a bit of Googling, I found this:

<?php if (get_the_modified_time() != get_the_time()) : ?>

		<div id="post-time">Created: <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?>, Updated: <?php the_modified_time('F j, Y'); ?> at <?php the_modified_time('g:i a'); ?></div>

	<?php else: ?>

		<div id="post-time">Created: <?php the_time('F j, Y'); ?> at <?php the_time('g:i a'); ?></div>

<?php endif; ?>

I then added this to the content-single.php file that I copied into the GP generic child theme. Added this CSS to style the output:

#post-time {
    font-size: 14px;
    color: red;
}

This is the result: The red, second line, is from the above code. The first line is from Tom's:

post-time-mod-time
Cheers!
Lyle

This archived topic is closed to new replies.