If you use the include_date="true"
parameter, Display Posts will include the post’s date using the (n/j/Y) format. Ex:
Recent Tutorials
- Display posts as a select dropdown (2/8/2021)
- Remove “by” when displaying author name (1/26/2021)
- Display specific posts (5/8/2020)
You can customize this using the date_format
parameter (see Formatting Dates and Times).
WordPress lets you specify a default date format in Settings > General > Date Format. If you would like to use that format in Display Posts, add the following code to your site:
This code snippet goes in a core functionality plugin or Code Snippets.
/**
* Display Posts - Default Date Format
* Uses format set in Settings > General > Date Format
* @link https://displayposts.com/2019/09/11/use-the-wordpress-date-format/
*/
function be_dps_date_format( $out, $pairs, $atts ) {
if( empty( $atts['date_format'] ) )
$out['date_format'] = get_option( 'date_format' );
return $out;
}
add_filter( 'shortcode_atts_display-posts', 'be_dps_date_format', 10, 3 );
Note: this only updates the default date format. You can still override this on a per-shortcode basis using the date_format
parameter in the shortcode.
Filters used:
shortcode_atts_display-posts