
WordPress Date & Time Tutorial For Beginners
- Updated On 23/04/2017
- Author : Pradeep Kumar
- Topic : WordPress
- Short URL : https://hellboundbloggers.com/?p=9009
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!
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.
YOU CAN ALSO SEARCH FOR YOUR DESIRED TOPICS:
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
-
Comments
Leave a Reply
13 Comments
Facebook Comments
Vinayak Nagri
I wanted it… thanks for sharing 😀
Digital Imagination
that’s nice….
but i knew this before itself…..
Mohana Krishnan.R.I
Wow… that’s Really Nice One Dude.. Thanks For Sharing.. 🙂
Baolin Liu
Great Info for Newbie Bloggers to think about…
Pooja
usefull tutorial for wordpress beginner's like us…
Robin
Thanks brother.. 🙂 will surely add one in my site.
– Robin
Tej Kohli
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
Web Self Service
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? 🙂
Luqman | Domain name registration
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.
Tek3D
I don’t understand what will appear in the display “Time Ago” function. It will display hours ago or days ago?
S.Pradeep Kumar
Displays minutes or hours or days! 🙂
Ajith Edassery
Looks like you are going to focus a lot on the WordPress how-tos? 🙂
S.Pradeep Kumar
Yea bro! Evergreen articles..! 😀