How to customize Date Format in Wordpress

2019-09-14 20:59发布

问题:

I need to customize the date format in Wordpress. I know that minor date changes can be made from Dashboard << Settings << General << Date. But my needs are not fulfilled from that.

I need that on post page, Month should have different font style and Day with a different font.

回答1:

If I'm understanding your question correctly, one solution would be to wrap each part of the date in a different span class. So whenever you want to insert the date you would use something like the following:

<?php the_time('F', '<span class="month">', '</span>'); ?>
&nbsp;
<?php the_time('d', '<span class="day">', '</span>'); ?>

Then you can target these different span classes separately in your css.

.month {
    font-family:serif;
}
.day {
    font-family:sans-serif;
}

This will output a format that looks like this: April 11 where both the month and date can be styled separately however you want. You can display a different month/date format by changing what you pass into the_time() function. For example, changing the month code to <?php the_time('m', '<span class="month">', '</span>'); ?> will output Apr 11 instead.

There are a lot of different configurations for this and there's more info on that here http://codex.wordpress.org/Formatting_Date_and_Time