Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1406792

    Hi folks. I would like to be able to print the current date in a button (or in a text box), together with some additional text (something like “Updates as of DD/MM/YYY”).

    After googleing, I’ve seen that you need some javascript:

    updates as of <script> date = new Date().toLocaleDateString();document.write(date);</script>

    I’ve tried entering this instruction both as a Button title of a button, and in the “Text” tab (not in the “Visual” tab) of a text box. It simply does not show the date but just the “Updates as of” string.

    Also this one does not work…
    Updates as of <div><script> date = new Date().toLocaleDateString();document.write(date);</script></div>

    Any idea on how I can get this done?
    THX
    bye!
    A.-

    #1406813

    try using that little snippet in your child theme functions.php:

    function show_date_with_shortcode() { 
      date_default_timezone_set('Europe/Berlin');
      setlocale(LC_TIME, 'de_DE.UTF-8');
      $date = date_i18n( 'l \d\e\n ' . get_option( 'date_format' ) . ' ' . get_option( 'time_format' ). ' \U\h\r'  );
      return $date ;
    }
    add_shortcode( 'show_date', 'show_date_with_shortcode' );

    use it as shortcode in your text : [show_date]

    this is for my german language a binding word \d \e \n will end in Freitag den 17.04.1968
    the rest will be corresponding to your lang settings – but if you like to have that binding word f.e. the then use \t\h\e
    if you don’t like the time in this shortcode – just remove that part:
    $date = date_i18n( 'l \d\e\n ' . get_option( 'date_format' ) );

    ___________

    or style a kind of calendar sheet:

    function datum_shortcode() {
      date_default_timezone_set("Europe/Berlin");
      setlocale(LC_TIME, 'de_DE.UTF8');
      $year = date_i18n('Y');
      $day = date_i18n('d');
      $month = date_i18n('F');
      $weekday = date_i18n('l');
      $weekdaycolor = date_i18n('l') == 'Sonntag' ? 'red': 'gray' ;
      $uhrzeit = date_i18n( get_option( 'time_format' ) );
    
      $datum = '<div id="calendar_sheet"><div class="month-year"><span class="month">'.$month.'</span><span class="year">' .$year.'</span></div><div class="day ' .$weekdaycolor.'">'.$day.'</div><div class="weekday">'.$weekday.'</div><div class="time">'.$uhrzeit.'</div></div>';
      return $datum;
    }
    add_shortcode('calendar_sheet', 'datum_shortcode');

    here use it as shortcode in your text: [calendar_sheet]

    some css for it:

    #calendar_sheet{
    text-align:center;
    display: inline-block;
    border:1px solid #eee;
    border-top:15px solid #0076ba;
    -webkit-box-shadow: 5px 5px 2px #ccc;
    -moz-box-shadow: 5px 5px 2px #ccc;
    box-shadow: 5px 5px 2px #ccc;
    background:#fafafa;
    padding: 5px;
    min-width: 150px;
    }
    
    .month-year .month,
    .month-year .year {
      padding: 0 5px
    }
    
    .day {
      font-size:48px;
      font-weight: bold;
      font-family: times;
      padding: 10px 0 0;
    }
    
    .day.red {
        color: red;
    }
    
    #calendar_sheet .time {
      font-size: 24px;
    }

    see both shortcodes in action on: https://enfold.webers-webdesign.de/3-columns/

    again adjust to your language: so for red Sundays change that Sonntag to Sunday in weekday color ;)
    and change to your local time in these lines:

    date_default_timezone_set("Europe/Berlin");
      setlocale(LC_TIME, 'de_DE.UTF8');
    • This reply was modified 1 year, 4 months ago by Yigit.
    #1406854

    Hi,

    Thanks for helping out @guenni007 :-)

    Best regards,
    Rikard

    #1407143

    Wow @Guenni007, one of your famous 200% complete answers, thanks! :)

    Actually, it’s fine for me to show the simple DD/MM/YYY date, therefore I am perfectly fine with the simpliest function:

    function displayTodaysDate( $atts )
     {
     return date(get_option('date_format'));
     }

    Thanks again or the hint!
    Bye,
    A.-

    #1407188

    Hi,

    Great, I’m glad that @guenni007 could help you out. Please let us know if you should need any further help on the topic, or if we can close it.

    Best regards,
    Rikard

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.