Home Display Time To Published or Scheduled Posts

    Display Time To Published or Scheduled Posts


    We wrote this snippet to support our article here, titled, “Static Day Countdown with WordPress Shortcode or PHP”. It’s another example of how the readable time difference function WordPress provides might be used.

    The function itself doesn’t do much but it can be incorporated into other tools to provide a more usable feature. As an example, if we want to display the time since our first (linked) article was published, I’ll use [timeago id="8724"]here[/timeago]. The result: 2 years ago (my bolding). It’ll either display X time ago or X time from now depending upon whether it’s published or scheduled.

    By default, $postdate will return local time (the second argument in get_post_time() determines if a GMT or local time is returned). An $offset (defined in your shortcode) will unlikely be necessary.

    Short URL for this post: http://shor.tt/17R0