Hiding the published-on date in old WordPress posts is requested in many Thesis Customizations. Sometimes this helps in avoiding the content to appear outdated, for the readers of your site.
In this post, I will show you how to hide the date in posts using the Thesis Theme custom files, without the need to tweak any of the core files. To know how – read on!
What we will do at the end of this tutorial?
We will try to do the following at the end of this very simple tutorial:
- Hide Published-on date in the Post Bylines for posts older than 30 days
- Also Hide these dates in Teasers – if the site is using any
Disable the Date Display in Thesis Options
Since we are coming up with our own logic to display the Dates, let us first disable the default date display in Thesis Theme.
To do this, go to WP Admin –> Thesis Options –> Display Options –> Bylines and un-check the “Show published-on date in post byline” option. (Don’t for to click the Big Ass Save Button !)
Now the dates magically disappear on the post bylines!
Hide Dates in Posts older than 30 days
Now on to the job! We will have to display the dates only in posts that were written in the last 30 days and hide them on older posts. To do this:
- Calculate the age of the current post – in number of days
- Display the date only if the posts was written in the last 30 days
The following code will help you calculate the age:
//Number of days this post is old $daysold = (current_time(timestamp) - get_the_time('U') - (get_settings('gmt_offset')))/(24*60*60);
To add this date to the Byline item, we would need to override the ‘thesis_hook_byline_item’. Following is the code does that will be added to the –
function add_date_to_byline() { //Number of days this post is old $daysold = (current_time(timestamp) - get_the_time('U') - (get_settings('gmt_offset')))/(24*60*60); if ($daysold ' . get_the_time(get_option('date_format')) . ''; } } add_action('thesis_hook_byline_item', 'add_date_to_byline');
This code, once added will hide dates in all posts older than 30 days.
Oh, we forgot the Teasers!
First we must hide the Date in Teasers, to make sure that the default behavior gets out of the way.
To do this, go to WP Admin –> Design Options –> Teasers –> Teaser Display Options and un-check the “date” option. (Don’t for to click the Big Ass Save Button !)
Now add the following code to your custom_functions.php and this will hide dates from posts older than 30 days, on teasers.
function add_date_to_teaser() { //Number of days this post is old $daysold = (current_time(timestamp) - get_the_time('U') - (get_settings('gmt_offset')))/(24*60*60); global $thesis_design; $date_formats = thesis_get_date_formats(); $use_format = ($thesis_design['teasers']['date']['format'] == 'custom') ? $thesis_design['teasers']['date']['custom'] : $date_formats[$thesis_design['teasers']['date']['format']]; if ($daysold ' . "\n"; } } add_action('thesis_hook_after_teaser_headline','add_date_to_teaser');
Note we are using the thesis_hook_after_teaser_headline hook for getting things done. Now we are truly done!
Credits
Following posts were useful in obtaining handy information for writing this tutorial.
- Removing the Date from Older Posts in WordPress
- Adding Date based Triggers to your Posts
Hope you found this post useful. If yes, please share it using Twitter and Facebook, for more readers to benefit