
-
AuthorPosts
-
November 29, 2018 at 10:27 am #1038866
Hi, I’m using blog template of Enfold, currently the template only displays date of my posts, but I need to display the hour, minute and second of posting, how to make that?
November 29, 2018 at 8:00 pm #1039144Hey sunwuye,
DO you mean on the single post?
Could you please give us a link to your website, we need more context to be able to help you.
Best regards,
VictoriaNovember 30, 2018 at 2:12 am #1039194Yes, please check my link below.
November 30, 2018 at 7:17 am #1039231Hi,
I found a code example to base this function on at this GitHub The example turned the date into a time and then calculated how long “ago” the post was posted, I removed the final calculation and was left with the date and exact time of the post. The date & time can be adjusted using the standard WordPress date & time format.
Try adding this code to the end of your functions.php file in Appearance > Editor:function mm_post_date_time( $formatted, $format, $the_post = false ) { if ( ! $the_post ) { global $post; $the_post = $post; } $post_date = get_post_time( 'M d Y g:i:s a', true, $the_post ); $output = $post_date; return $output; } add_filter( 'the_time', 'mm_post_date_time', 10, 2 ); add_filter( 'get_the_time', 'mm_post_date_time', 10, 3 ); add_filter( 'the_date', 'mm_post_date_time', 10, 2 ); add_filter( 'get_the_date', 'mm_post_date_time', 10, 3 );
Best regards,
MikeNovember 30, 2018 at 8:08 am #1039245Thanks Mike, could you tell me where to edit the time format? I tried to replace ‘M d Y g:i:s a’ part, but no change happened.
And how to display my local time, which is UTC+8?
-
This reply was modified 6 years, 7 months ago by
sunwuye.
November 30, 2018 at 3:02 pm #1039329Hi,
To change the format edit the ‘M d Y g:i:s a’ part, following the link above. This works on my localhost, so it should work for you too. Or see if changing the format at WordPress > Settings > General > Date Format makes a difference, it does not for me.
What format are you trying for?
As for local time vs server time, I will have to research this more.Best regards,
MikeDecember 1, 2018 at 4:38 am #1039478Hi Mike, the format has changed now, thanks! And I edited functions-enfold.php instead of functions.php, and it works as well, hope there would be no other error.
I have to display the local time because this is required by Baidu in China now, so that it could better identify original content.
It seems that the “current_time” code needs to be edited (<?php $time = current_time( $type, $gmt = 0 ); ?>
) according to this page: https://codex.wordpress.org/Function_Reference/current_time, but I cannot find such code anywhere,-
This reply was modified 6 years, 7 months ago by
sunwuye.
December 1, 2018 at 7:53 am #1039531Hi,
Thanks for the link it did help lead me to the correct function, so what you will need to do is ensure that WordPress > Settings > General > Timezone is set correctly, there is a info box that tells you what WordPress thinks is the local time which updates when you save the settings:
Then change the function to this one:function mm_post_date_time( $formatted, $format, $the_post = false ) { if ( ! $the_post ) { global $post; $the_post = $post; } $post_date = get_post_time( 'M d Y g:i:s a', $gmt = 0, $the_post); $output = $post_date; return $output; } add_filter( 'the_time', 'mm_post_date_time', 10, 2 ); add_filter( 'get_the_time', 'mm_post_date_time', 10, 3 ); add_filter( 'the_date', 'mm_post_date_time', 10, 2 ); add_filter( 'get_the_date', 'mm_post_date_time', 10, 3 );
Best regards,
MikeDecember 3, 2018 at 3:10 am #1040081Great, it works now, thanks Mike!
December 3, 2018 at 9:26 am #1040184Hi sunwuye,
Glad that we could help. :)
Let us know if you need further assistance or if we can close this thread.Best regards,
NikkoDecember 4, 2018 at 1:37 pm #1040715So is it OK to just put the codes in the end of the functions-enfold.php or functions.php file?
December 4, 2018 at 2:46 pm #1040736 -
This reply was modified 6 years, 7 months ago by
-
AuthorPosts
- The topic ‘How to display exact posting time?’ is closed to new replies.