Formatted Date and Time Shortcode
Shortcode [current_date] outputs the current date/time in the site's timezone using any PHP date format.
PHPby SnipCraft
php
<?php
/**
* Usage: [current_date]
* Optional: [current_date format="F j, Y"] or [current_date format="H:i"]
* Accepts any PHP date() format string. Defaults to the site's Date Format setting.
*/
add_shortcode( 'current_date', 'scseed_formatted_date_shortcode' );
function scseed_formatted_date_shortcode( $atts ) {
$atts = shortcode_atts(
array( 'format' => get_option( 'date_format' ) ),
$atts,
'current_date'
);
// Sanitize: allow only safe date-format characters
$format = sanitize_text_field( $atts['format'] );
return esc_html( wp_date( $format ) );
}#date#display#dynamic#shortcode#time