- This topic has 7 replies, 3 voices, and was last updated 3 years, 5 months ago by
Ying.
-
AuthorPosts
-
November 6, 2022 at 9:48 am #2403822
Quested
Hi awesome people.
Hope you enjoyed your weekend. One of my client want to add Post Time on Archive Posts Meta. Can you guide me how can I achieve this.
Humble Regards
November 6, 2022 at 6:39 pm #2404082Fernando Customer Support
Hi Quested,
To clarify, are you referring to adding an “Estimated Time to read”?
If so, you can add this PHP snippet:
function tu_estimated_reading_time() { ob_start(); $post = get_post(); $content = $post->post_content; $wpm = 300; // How many words per minute. $clean_content = strip_shortcodes( $content ); $clean_content = strip_tags( $clean_content ); $word_count = str_word_count( $clean_content ); $time ='<div class="read-time"><span class="gp-icon">•</span>Reading time: '. ceil( $word_count / $wpm ) . ' minutes'. '</div>'; return $time; return ob_get_clean(); } add_shortcode('tu_reading_time', 'tu_estimated_reading_time');Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
Then, add a Shortcode Block to your Block Element – Content Template, and add this code:
[tu_reading_time]November 7, 2022 at 9:10 am #2405082Quested
Thank you for relying back.
Actually I want to know how can I add time on meta post.
Example:- 6:30 hours agoNovember 7, 2022 at 11:29 am #2405257Ying
StaffCustomer SupportHi there,
Do you mean you don’t want to show the post date, but only the xx hours ago or xx days ago?
Or do you just simply want to add the time together with the post date?
November 7, 2022 at 2:05 pm #2405388Quested
I want to show post date as (October 11, 2022). But on a Custom Post Type (Dialy Posts) I want to have hours ago option.
Example: 9:10 hours agoNovember 7, 2022 at 4:47 pm #2405500Ying
StaffCustomer SupportYou can add an additional CSS class to the headline block which represnet the date, eg.
my-date, then add this PHP snippet:add_filter( 'render_block', function( $block_content, $block ) { if ( ! empty( $block['attrs']['className'] ) && 'my-date' === $block['attrs']['className'] ) { $my_date = sprintf( esc_html__( '%s ago', 'textdomain' ), human_time_diff(get_the_time ( 'U' ), current_time( 'timestamp' )) ); $block_content = sprintf( '<time class="entry-date published" datetime="%1$s">%2$s</time>', esc_attr( get_the_date() ), $my_date ); } return $block_content; }, 10, 2 );November 7, 2022 at 5:20 pm #2405526Quested
You guys are awesome.
Thank you so much for your help.
November 7, 2022 at 5:33 pm #2405531Ying
StaffCustomer SupportYou are welcome 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.