WordPress Date & Time Tutorial For Beginners

Written by in WordPress - Print This Post



In this article I’m going to share some tips for displaying date and time on WordPress posts and comments information.

Though I’m 99.9% sure, I recommend you to take backup of your theme files or at least the required theme file. Please!

Display “Time Ago” for Posts or Comments

Just copy and paste the following code in functions.php file.

function time_ago( $type = 'post' ) {
$d = 'comment' == $type ? 'get_comment_time' : 'get_post_time';
return human_time_diff($d('U'), current_time('timestamp')) . " " . __('ago');
}

This uses built-in WordPress function human_time_diff(). Now place the following PHP code on single.php file or comments.php.

Note : File names may vary according to themes.

<?php echo time_ago(); ?>


Display Copyright Year

We don’t need to add copyright date or time, displaying the year is more than enough.

Add the following code in footer.php (most preferred area).

Coding :

Copyright © <?php the_time('Y'); ?> < ?php bloginfo('name'); ?>

Output :

Copyright © 2009 HellBound Bloggers

Tip : Update The Copyright Year Automatically


Adding the Date and the Time to your posts

You can add date and time to your posts in this format easily.

This entry was posted on <?php the_time('l, F jS, Y') ?> at < ?php the_time('g:i a'); ?> and is filed under <?php the_category(', ') ?>

Output :

This entry was posted on 21 July 2010 at 06:00 PM and is filed under Resources


Display the Date and the Time your post was modified

The template tag the_modified_date shows the date your post was last modified. Similarly the_modified_time() displays the last modified time.

Note : These only work when used within the WordPress Loop.

Coding :

This post was published on <?php the_date('F j, Y'); ?> and was last modified on < ?php the_modified_date(); ?> at <?php the_modified_time() ?>

Output :

This post was published on July 18, 2010 and was last modified on July 20, 2010 at 5:30 pm

For further formatting and customizing, check WordPress Codex.

Having any problems? Do you know any other trick? Please share it in the comments!









HBB RSS
Hello there! If you are new here, you might want to subscribe to the RSS feed for updates on this topic. You will also get instant access to 100+ HBB Guides & Tutorials.
If you wish to subscribe here via Email, then kindly click here.



Editor-in-Chief and Owner of 20 Years Old Kiddo, Open Source Enthusiast, Tech Blogger, Striving Entrepreneur, and a Typical Engineering Student. Addicted to Blogging, Walking and Messing. Catch him on Facebook, Twitter and .


HBB has 664+ Awesome Contributors. [Join HBB].

HellBound Bloggers (HBB) is a part of Slashsquare Network.






13 Responses to “WordPress Date & Time Tutorial For Beginners”

Leave a Reply


Comments Policy | Brand Your Comments | Do Follow Blog | Top Commentators Award


REFERENCE : 7 Tips To Be A Hero On Blog Commenting [HELPFUL]


Overall HellBound Bloggers (HBB) has 23,558 Genuine Comments and Yours Will Add More Value To It.




Previous Article:

Next Article:

  1. Looks like you are going to focus a lot on the WordPress how-tos? :)

  2. Tek3D says:

    I don’t understand what will appear in the display “Time Ago” function. It will display hours ago or days ago?

  3. Thanks for sharing this Pradeep, like date and time to be display on my blog, I am going to try the code when I have time to do this.

  4. Thanks for sharing this, but I have to backup first before integrating this like what you said. What other tips do you have for WP beginners? :)

  5. Tej Kohli says:

    How Can I change date to previous date , Suppose my Old Blog is deleted and I want to post same post as I posted before .. I want the same date on that time

  6. Robin says:

    Thanks brother.. :) will surely add one in my site.

    - Robin

  7. Pooja says:

    usefull tutorial for wordpress beginner's like us…

  8. Baolin Liu says:

    Great Info for Newbie Bloggers to think about…

  9. Wow… that’s Really Nice One Dude.. Thanks For Sharing.. :)

  10. that’s nice….

    but i knew this before itself…..

  11. I wanted it… thanks for sharing :D



Subscribe without commenting




COPYRIGHT © 2012 SLASHSQUARE NETWORK. REPRODUCTION WITHOUT EXPLICIT PERMISSION IS PROHIBITED. ALL RIGHTS RESERVED.

Slashsquare
Mobile Version · About Us · Contact Us · Subscription · Advertise · Review · Write For Us · Archives · Privacy Policy · Disclaimer
Loading...
ViperBarUp
ViperBarDown