Archived topic
Clock/time shortcode
20 replies · Started by JOAQUIM GALANTE on May 25, 2020
Hi, the shortcode in code-snippets
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( ‘%3$s‘,
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
$time_string
);
return $date;
} );
have several errors of syntax, can you help me ?
https://focusmsn.pt/wp-content/uploads/2020/05/Relogio-shortcode.png
Hi there,
Is this the code you are using?
https://generatepress.com/forums/topic/shortcode-for-current-date/#post-632065
Looks like you are using the wrong quotation marks.
Should be "" and not ”.
Simply copying and past the code should work though.
Thanks leo, now the date is on but appear 23/05/2020 instead 25/05/2020. :)
What can i do to put the right date and show the day and hour ?
Hi there,
Try setting your date format in Settings > General.
The date format is right on general settings. When i put the custom_date shortcode in a widget the date appears with two days behind, the hour is hide, day of the week hide too :)
I thought that inserting the clock on the page was simple but it is not. At least for me. I think I will give up.
Thanks to all for the help.
The shortcode there will display the published date of the current post using your date format settings.
It will also add the updated date, but will hide it with CSS.
In the general settings the things look fine. A few days ago David told me to insert the code with code-snippets plugin and put the short code custom_date in a widget :)
It is very confusing to me :(
Tom, is it possible have on the site something like this ? https://focusmsn.pt/top-bar
What date format and time format are you using?
A top bar like that would require custom development.
Hi Tom, the top bar don't need to be exactly the same, on the breaking news only the letters without images is enough. A custom development have costs ?
Date and time format in general settings https://focusmsn.pt/general
You can always add your own text to the Top Bar and customize its look in the Customizer.
As for the date, I see now that the format isn't the issue - the issue is the actual date that's displaying?
The date right now is displaying the published date of the post. What date would you prefer?
I prefer the timer displaying actual day, date and hour to put in a top bar.
In that case, you'd do something like this:
add_shortcode( 'current_date', function() {
return date( get_option( 'date_format' ) );
} );
Nothing happens, the only thing new is the shortcode [custom_date] appear in frontpage.
Remove the [custom_date] shortcode
And add [current_date]