- This topic has 7 replies, 2 voices, and was last updated 4 years, 7 months ago by
Elvin.
-
AuthorPosts
-
August 4, 2021 at 7:27 pm #1884316
nomadiceman
I’ve got the meta date set up which is great. But I would like to include the Time a post was posted
How can I do that?
August 4, 2021 at 7:29 pm #1884318Elvin
StaffCustomer SupportHi there,
Any specific layout on how you want it to be displayed? Do you want both the publish date and the update date to display at the same time?
Let us know. 😀
August 4, 2021 at 7:33 pm #1884322nomadiceman
I was just thinking of having the time after the date as its a news site
something like this
www.arabianbusiness.com/real-estate/466741-dubai-broker-sees-surge-in-british-property-buyers-amid-uaes-latest-expat-incentivesAugust 4, 2021 at 7:52 pm #1884333Elvin
StaffCustomer SupportAh my bad, I misread the question.
Try this PHP filter.
add_filter( 'generate_post_date_output', function($post_date){ if( is_singular() ){ $post_date = sprintf( '<time class="entry-date published" datetime="%1$s"><span class="entry-date">%2$s</span><span class="time">%3$s</span></time>', esc_attr( get_the_date( 'c', $id ) ), esc_html( get_the_date( 'F j, Y', $id ) ), esc_html( get_the_time( ' g:i A ', $id ) ) ); return $post_date; } return $post_date; },15,2);August 4, 2021 at 8:09 pm #1884339nomadiceman
Ive added that snippet and cleared the caches but the Time doesn’t show.
You can see in the supplied link. The date published shows, but no time
August 4, 2021 at 9:59 pm #1884391Elvin
StaffCustomer SupportAh I see. You’re using block element’s dynamic post meta.
In that case, the snippet won’t work because that’s for the theme default post date output.
That said, try this:
If it’s only for the published date, try this PHP snippet:
add_filter( 'generate_dynamic_element_text', function( $post_date, $block ){ if ( 'post-date' === $block['attrs']['gpDynamicTextType'] && empty($block['attrs']['gpDynamicDateType']) ) { $post_date = sprintf( '<time class="entry-date updated-date" datetime="%1$s">%2$s</time>', esc_attr( get_the_date( 'c', $id ) ), esc_html( get_the_date( 'F j, Y g:i A', $id ) ) ); } return $post_date; },15,2);If you want the modified date to have time as well, try this:
add_filter( 'generate_dynamic_element_text', function( $post_date, $block ){ if ( 'post-date' === $block['attrs']['gpDynamicTextType'] && empty($block['attrs']['gpDynamicDateType']) ) { $post_date = sprintf( '<time class="entry-date updated-date" datetime="%1$s">%2$s</time>', esc_attr( get_the_date( 'c', $id ) ), esc_html( get_the_date( 'F j, Y g:i A', $id ) ) ); } if ( 'post-date' === $block['attrs']['gpDynamicTextType'] && 'updated-date' === $block['attrs']['gpDynamicDateType'] ) { $post_date = sprintf( '<time class="entry-date updated-date" datetime="%1$s">%2$s</time>', esc_attr( get_the_modified_date( 'c', $id ) ), esc_html( get_the_modified_date( 'F j, Y g:i A', $id ) ) ); } return $post_date; },15,2);August 4, 2021 at 10:04 pm #1884393nomadiceman
perfect thank you
August 8, 2021 at 8:35 pm #1888618Elvin
StaffCustomer SupportNo problem. glad to be of any help. 😀
-
AuthorPosts
- You must be logged in to reply to this topic.