Skip to content

Instantly share code, notes, and snippets.

@BenSibley
Created December 16, 2020 19:25
Show Gist options
  • Save BenSibley/5000395b0a102f078d3adf994370fd84 to your computer and use it in GitHub Desktop.
Save BenSibley/5000395b0a102f078d3adf994370fd84 to your computer and use it in GitHub Desktop.
Mission News date fix
function ct_mission_news_post_byline( $author, $date, $categories ) {
if ( $author == 'no' && $date == 'no' && $categories == 'no' ) {
return;
}
if ( empty($author) ) {
$author = 'yes';
}
if ( empty($date) ) {
$date = 'yes';
}
$post_author = get_the_author();
// add compatibility when used in header before loop
if ( empty( $post_author ) ) {
global $post;
$post_author = get_the_author_meta( 'display_name', $post->post_author );
}
$post_date = date_i18n( get_option( 'date_format' ), strtotime( get_the_date('c') ) );
echo '<div class="post-byline">';
if ( $author == 'no' ) {
echo esc_html( $post_date );
} elseif ( $date == 'no' ) {
// translators: %s = the author who published the post
printf( esc_html_x( 'By %s', 'This blog post was published by some author', 'mission-news' ), esc_html( $post_author ) );
} else {
// translators: %1$s = the author who published the post. %2$s = the date it was published
printf( esc_html_x( 'By %1$s on %2$s', 'This blog post was published by some author on some date ', 'mission-news' ), esc_html( $post_author ), esc_html( $post_date ) );
}
// Add optional post category
if ( $categories == 'yes' ) {
if ( $author == 'yes' || $date == 'yes' ) {
echo ' | ';
}
ct_mission_news_byline_categories();
}
echo '</div>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment