I have WordPress theme and I use get_the_date function to display post data :

<?php echo get_the_date( 'M-d-y' ); ?>

But it seems it will be better to use get_option( 'date_format' ).

How can I display post data using get_option function?


Calling get_the_date( get_option('date_format') ); will return the exact same value as get_the_date(); this is because by default if a date format is not specified when the function is called it will use get_option('date_format'); as can be seen from the following snippet taken from the get_the_date() function itself:

if ( '' == $d ) {
    $the_date = mysql2date( get_option( 'date_format' ), $post->post_date );
} else {
    $the_date = mysql2date( $d, $post->post_date );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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