[Resolved] How to shorten month name?

Home Forums Support [Resolved] How to shorten month name?

Home Forums Support How to shorten month name?

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1586466
    Matic

    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

    #1586889
    David
    Staff
    Customer Support

    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' );
    #1587205
    Matic

    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

    #1587309
    David
    Staff
    Customer Support
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.