• Resolved Karl

    (@yitschak)


    Hi Guys,

    I was trying to display the current date on “text” widget of my site and tried to add this: <?php the_time(‘j F Y’); ?> – but it’s not showing. Please help.

    Thanks, Karl

Viewing 5 replies - 1 through 5 (of 5 total)
  • Try the Exec PHP plugin.

    i agree with @vtxyzzy

    additionally,
    the current date would be something like:

    <?php echo date('j F Y'); ?>

    https://php.net/manual/en/function.date.php

    you code would show the publish date of probably the last post in the main content (unpredictably depending on the location of your textwidget)

    or alternatively use some javascript in the textwidget; for instance (https://www.mediacollege.com/internet/javascript/date-time/):

    <script type="text/javascript"><!--
    var date = new Date();
    var d  = date.getDate();
    var day = (d < 10) ? '0' + d : d;
    var m = date.getMonth() + 1;
    var month = (m < 10) ? '0' + m : m;
    var yy = date.getYear();
    var year = (yy < 1000) ? yy + 1900 : yy;
    
    document.write(day + "/" + month + "/" + year);
     //--></script>
    Thread Starter Karl

    (@yitschak)

    Thanks so much guys this is a big help… Another question: How can I place the current date on any part of site for example placing it on paragraph on post/page area. any idea?

    Your responses is greatly appreciated.

    I would create a shortcode function that would return the date. That shortcode could be used in the content of a post or page, but to use it in a text widget, you will have to add the do_shortcode filter to the widget_text hook:

    add_filter('widget_text','do_shortcode');
    Thread Starter Karl

    (@yitschak)

    thank you vtxyzzy. it’s a big help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘add current date in "text" widget’ is closed to new replies.