0

Can this line:

$message = str_replace( '[post_date]', $post->post_date, $message );

be modified so the date displayed for the [post_date] shortcode is formatted as Saturday, 12/03/16, 08:43 ?

Thanks!

1

Instead of using $post->post_date, use get_the_time( $format, $post ).

The correct PHP date format string for your question is 'd/m/y H:i'.

... Assuming you want a two digit minute (even when less that 10 minutes). Also, I may have the month and day the wrong way around for you.

The format argument in get_the_time() is PHP's native date format - http://php.net/manual/en/function.date.php

Then, change your line of code to:

$message = str_replace( '[post_date]', get_the_time( 'd/m/y H:i', $post ), $message );

Though, I think it'll be easier and neater to just add the get_the_time( 'd/m/y H:i', $post ) to your template, rather than having to put a shortcode into each post.

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.