Show date as: Published on {date} at {time} | Updated on {date} at {time}
add_filter( 'generate_post_date_output', 'tu_show_modified_date' ); | |
function tu_show_modified_date() { | |
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>'; | |
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { | |
$time_string = 'Updated on: <time class="updated" datetime="%3$s" itemprop="dateModified">%4$s</time>'; | |
} | |
$time_string = sprintf( $time_string, | |
esc_attr( get_the_date( 'c' ) ), | |
esc_html( get_the_date() ), | |
esc_attr( get_the_modified_date( 'c' ) ), | |
esc_html( get_the_modified_date() ) | |
); | |
// If our date is enabled, show it. | |
printf( '<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 | |
) | |
); | |
} |
This comment has been minimized.
This comment has been minimized.
Hey @brianleejackson - sorry I didn't see your comment! I wonder if the above would work better? It should show the published date unless the post has been updated, at which point is shows the updated date. Includes schema as well. Let me know! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Hey Tom! This is exactly what I need... however, I think you forgot about schema. Can you edit it and add the correct itemprop, etc... to it?
Thanks man.