Make Money Online Queries? Struggling To Get Traffic To Your Blog? Sign Up On (HBB) Forum Now!

WordPress Date & Time Tutorial For Beginners

CONNECT WITH HBB ON SOCIAL MEDIA

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!



By

CEO and Founder of Slashsquare, Indian Blog Network and Web Consulting Media. HBB is a part of Slashsquare Network. I'm a Tech Blogger, Striving Entrepreneur, Atheist, and Proud Indian. Catch me on Facebook and Twitter.

  • My Website

Want to discuss your queries and interact with experts? You can connect with HellBound Bloggers (HBB) Facebook group for free!

Join HellBound Bloggers (HBB) and get Instant Updates. We'll also notify you with Great Deals, Discounts and other Interesting Tips. We won't SPAM or SHARE your Email Address with anyone.

Thank you for reading! We welcome and appreciate your comments, but at the same time, make sure you are adding something valuable to this article. If you have any serious queries, suggestions or anything related to this article, feel free to share them, we really appreciate that.

But, if your blog comments are a random "Thank you", "Useful Post", or anything that doesn't actually upscale the article, then we'll be removing them and it won't be appeared below. Thanks for understanding and thanks for connecting with us. If you want to give us any feedback or report any errors, you can kindly contact us and we'll revert back soon.

  • Comments
  • Facebook Comments