Display Posts Shortcode
[resolved] show date in format: D/M/Y (4 posts)

  1. mrgoolie
    Posted 4 years ago #

    Does anybody know how to format the date so instead of M/D/Y you get D/M/Y:)


  2. Bill Erickson
    Plugin Author

    Posted 4 years ago #

    You'll need to use the output filter to modify the date, as the format is not editable through the shortcode. Something like this would go in your functions.php file:


    More info on date formats

  3. keeters
    Posted 4 years ago #

    Bill, this is a great plug-in! There was a small error in your filter code, which i have updated below.

    add_filter( 'display_posts_shortcode_output', 'be_display_posts_date', 10, 7 );
    function be_display_posts_date( $output, $atts, $image, $title, $date, $excerpt, $inner_wrapper ) {
    // Change the date
    if ( $atts['include_date'])
    $date = ' <span class="date">('. get_the_date('j/n/Y') .')</span>';
    else $date = '';
    // Now let's rebuild the output.
    $output = '<' . $inner_wrapper . ' class="listing-item">' . $image . $title . $date . $excerpt . '</' . $inner_wrapper . '>';
    // Finally we'll return the modified output
    return $output;
  4. Bill Erickson
    Plugin Author

    Posted 4 years ago #

    Good catch! Yeah, this code was untested so I just copied the date part directly out of the plugin. Since the attributes haven't been parsed yet, your approach is needed. I've updated the code.

    Another approach would be to check if( !empty( $date ) )

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Display Posts Shortcode
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic