Site logo

Archived topic

Clock/time shortcode

20 replies · Started by JOAQUIM GALANTE on May 25, 2020

Viewing posts 1–15 of 21

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

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 :(

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]

This archived topic is closed to new replies.