Add current time/date to pro header

Hi,
can you help me to add a “simple” time/date stamp to my pro header?

I’ve create a event page and it would be nice to see the actually time/date also above the page, in the pro header.
Which kind of element i need to add and some php code i think, or?

Kind Regards,
Stefan

Hi There,

Please add this code to your functions.php file locates in your child theme:

add_shortcode( 'current_date', 'func_current_date' );
function func_current_date(){
  return date('d/m/y hh:mm');
}

Then you can use the [current_date] to get the current date time.

Regards!

1 Like

Nearly perfect, thank you :slight_smile:

Regards!

You’re welcome!
Thanks for letting us know that it has worked for you.

I’m sorry me again, i thought i can did it by myself, but i won’t :confused:
Can you help me to rebuild the code to get some text in the date, like this:

“Es ist Samstag (saturday), der 03.02.2018 und 15 Uhr”

I don’t get the text in it and the Weekday is in english.

Regards :blush:

Hi There,

Please try with this code instead:

add_shortcode( 'current_date', 'func_current_date' );
function func_current_date(){
  setlocale(LC_TIME, 'de_DE', 'deu_deu');
  $tz_object = new DateTimeZone('Europe/Zurich');
  $datetime = new DateTime();
  $datetime->setTimezone($tz_object); 
  echo 'Es ist '.date('l').', der '.date('d.m.Y').' und '.date('H').' Uhr;';
}

Hope it helps :slight_smile:

1 Like

It won’t change the Weekday to german, but i google around and “copy” and paste the code with snippets to this:

 add_shortcode( 'current_date', 'func_current_date' );
function func_current_date(){
$loc=setlocale(LC_ALL, 'de_DE@euro', 'de_DE', 'deu_deu');
date_default_timezone_set('Europe/Berlin');
return 'Es ist ' . strftime('%A ') . date('H:i') . ' Uhr' . ', dem ' . date('d.m.Y');
}

And it seems it works, is it “okay” so long?

Regards,

Sorry another answer.
With the “echo” output from your code it is set up above the headline element.
I’ve added the code to a “headline” element as subtitle and insert the “shordtcode” and it was below it,
Now its every time above, don’T matter if i set it to “reverse” or something like this.

Regards,

Hi There,

Please replace the echo with return.

Regards!

1 Like

Insane, thank you so much!

You are welcome!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.