Last active
January 23, 2019 07:09
-
-
Save generatepress/8bc94ae43f67c40a077aefc8ec970fd0 to your computer and use it in GitHub Desktop.
Show date as: Published on {date} at {time} | Updated on {date} at {time}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
) | |
); | |
} |
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
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.