Skip to content

Instantly share code, notes, and snippets.

Created November 2, 2017 14:26
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 anonymous/1041b9adc58a1a84a57efe96af2f33e4 to your computer and use it in GitHub Desktop.
Save anonymous/1041b9adc58a1a84a57efe96af2f33e4 to your computer and use it in GitHub Desktop.
WordPress Entry Date Template Function
<?php
if ( ! function_exists( 'theme_slug_entry_date' ) ) :
/**
* Displays the post date
*/
function theme_slug_entry_date() {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s">%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() )
);
$posted_on = sprintf(
esc_html_x( 'Posted on %s', 'post date', 'theme-slug' ),
'<a href="' . esc_url( get_permalink() ) . '" rel="bookmark">' . $time_string . '</a>'
);
return '<span class="meta-date">' . $posted_on . '</span>';
}
endif;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment