Archived topic
Shortcode for current date
7 replies · Started by david on July 23, 2018
hello,
how to get current date with shortcode?
Hi there,
This post should help:
https://generatepress.com/forums/topic/changing-the-copyright-message-full-date/
hello, your code works. i need a little further help.
my default language on wordpress is indonesian. how to make the shortcode works like {{post_date}} on page header? the page header use wordpress language i set. the shortcode you provide use english as date
You can just use the shortcode inside the Page Header.
It should use whatever language you have set: https://codex.wordpress.org/Formatting_Date_and_Time
no tom, i'd like to use on post. but it's output is english. i already use {{post_date}} on page header
i'd give you a visual

i'd like to get juli 2018 as result instead of july 2018
Try this for your shortcode:
add_shortcode( 'custom_date', function() {
$time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string .= '<time class="updated" datetime="%3$s" itemprop="dateModified" style="display:none;">%4$s</time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
$date = sprintf( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>',
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
$time_string
);
return $date;
} );
thanks tom, it works perfectly!
You're welcome :)