• Hi guys,

    I am wondering how I can use PHP code to automatically update the date each month, for my sites top post here:

    https://www.linkvana.info/

    At the moment where it says “Update – September, 2010” I am doing it manually each month, but I know PHP would easily manage changing this automatically based on the current month..

    Just not sure how to implement it into a wordpress post, and the right code to use, etc..

    Any help?

    Thanks,

    Nick

Viewing 7 replies - 1 through 7 (of 7 total)
  • Not quite sure what you want. If you need the current date to always show in selected posts, you could use a shortcode. Add the function to your functions.php, and put the shortcode [current_date] in the posts.

    <?php
    function current_date_func() {
       // Usage: [current_date]
      return date('F, Y');
    }
    add_shortcode('current_date','current_date_func');
    ?>
    Thread Starter Jase07

    (@jase07)

    Great!

    can that work for just the current month? ie :

    Updated – <php>current-month</php> (i obviously don’t know PHP : ) )

    Thanks for your help,

    Nick

    Hi jase,
    i think if you change return date(‘F, Y’); to
    return date(‘M’);
    it will return just the month.
    David

    return date('M'); will return the 3-letter abbreviation for the month.

    return date('F'); will return the full month name.

    In your post, put this:

    Updated – [current_date]

    If this solves your problem, please use the dropdown at top right to mark this topic ‘Resolved’.

    Thread Starter Jase07

    (@jase07)

    Thanks guys, you rock!

    You are welcome!

    Thread Starter Jase07

    (@jase07)

    Hi,

    Don’t know if this will reopen the thread, but im just wondering how to add the year to the above solution. So right now I have:

    Updated – [current_date]

    which is coming out as:

    Updated – March

    but then I am having to change the year manually ( i know, once every year big deal hey : ) )

    but still, what code would I put in, in order to get:

    Updated – March, 2011

    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘How Can I Add PHP Code For Date Variables Into A Post?’ is closed to new replies.