Archived topic
How to shorten month name?
3 replies · Started by Matic on December 18, 2020
Hi,
I am using shortcode [modified_date] that calls the following PHP function:
function post_modified_date() {
return get_the_modified_date();
}
add_shortcode( 'modified_date', 'post_modified_date' );
This returns a date in the following format: December 18, 2020. How can I make it so that every month would be shortened to 3 letter only followed by a dot, so it would read: Dec. 18, 2020?
Cheers,
Matic
Hi there
the get modified date function supports different format arguments - examples here:
https://wordpress.org/support/article/formatting-date-and-time/#format-string-examples
Looking at the example you would need to use:
function post_modified_date() {
get_the_modified_date( 'M j, Y' )'
}
add_shortcode( 'modified_date', 'post_modified_date' );
Thank you for the link! I don't know how I missed it.
Your code didn't work because it needed some additional tweaking.
For anyone else with the same problem, the code that worked for me:
function post_modified_date() {
return get_the_modified_date('M. j, Y');
}
add_shortcode( 'modified_date', 'post_modified_date' );
Thank you for your help!
Cheers,
Matic
Glad to hear that.