0

I would like to remove the comma persent in the entry-date in the entry footer of Twent-Sixteen theme for styling purposes. (Month-Date, 2016) Looks like the date is coming from the function below. But I cannot figure out from where the comma after Month-Date comes in?

function twentysixteen_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' ) ),
        get_the_date(),
        esc_attr( get_the_modified_date( 'c' ) ),
        get_the_modified_date()
    );

    printf( '<span class="posted-on"><span class="screen-reader-text">%1$s </span><a href="%2$s" rel="bookmark">%3$s</a></span>',
        _x( 'Posted on', 'Used before publish date.', 'twentysixteen' ),
        esc_url( get_permalink() ),
        $time_string
    );
}
endif;

1 Answer 1

0

get_the_date and get_the_modified_date use the date_format option set on the Settings -> General screen. Changing your date format there should change the date formatting returned by these functions without having to change TwentySixteen.

You can also use the filters of the same names to conditionally filter the dates depending on conditions. For example, show a different date format on pages:

add_filter('get_the_date','custom_get_the_date',10,3);
function custom_get_the_date($the_date, $d, $post) {
    if (is_page()) { // date display on pages
        $d = 'jS M Y'; // custom date format, see PHP date function
        $post = get_post($post); if (!$post) {return $the_date;}
        $the_date = mysql2date( $d, $post->post_date);
    }
    return $the_date;
}

add_filter('get_the_modified_date','custom_get_the_modified_date',10,2);
function custom_get_the_modified_date($the_time, $d) {
    if (is_page()) {
        $d = 'jS M Y'; // custom date format, see PHP date function
        $the_time = get_post_modified_time($d, null, null, true);
    }
    return $the_time;
}
2
  • Thank you so much for your answer majick! Thank solved it! I wish I had the reputation to upvote this here! :) Apr 26, 2016 at 0:44
  • accepted answer is better I think anyway. :-) I added some notes on the available filters also.
    – majick
    Apr 26, 2016 at 0:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.