Skip to content

Instantly share code, notes, and snippets.

@generatepress
Created September 30, 2018 01:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save generatepress/ba6e3febda3b856b8c3ac29fd5054ce6 to your computer and use it in GitHub Desktop.
Save generatepress/ba6e3febda3b856b8c3ac29fd5054ce6 to your computer and use it in GitHub Desktop.
Show only the updated date if set
add_filter( 'generate_post_date_output', function( $output, $time_string ) {
$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 = '<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() )
);
return sprintf( '<span class="posted-on">%s</span>', // WPCS: XSS ok, sanitization ok.
$time_string
);
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment