Hide Dates in Old WordPress Posts using Thesis Theme

thesis-hide-old-posts

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 – /custom/custom_functions.php file.

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


Share this post:

Post on Twitter
Share on Facebook

Thoughts Unlimited runs on Genesis Framework


Comments

  1. So cool! I've done this on my blog and it works great. Except there was one typo in the “echo” statement for the teasers. There's a . Fixed that and all is well.

    Thanks so much!

  2. Pam,

    Great that you found it useful… Keep visiting for more such useful ideas :)

  3. Hi Ashwin,

    Just wanted to say that you keep coming up with really helpful WP code that is EASY TO IMPLEMENT!This is the 2nd piece of code I'm lifting blind from your site… :-)

    Cheers,
    AviD

  4. Hey AviD,

    Great that you found it useful. Happy times with Thesis :)

    Regards,
    Ashwin

  5. A bit of help Ashwin….

    I'd like to integrate the following piece of code for my site with your code. Any ideas?

    // Custom Byline Function
    function custom_byline() {
    echo '

    Updated on ' . get_the_time(get_option('date_format'));
    if (!is_single())
    echo ' |  Posted In ' . get_the_category_list(',');
    echo '

    ';
    }
    add_action('thesis_hook_after_headline', 'custom_byline');

  6. This should be the merged code.

    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 if (!is_single()) {
    echo '' . 'Updated On ' . get_the_time($use_format) . ' | Posted In ' . get_the_category_list(','). '' . “n”;
    echo ' | Posted In ' . get_the_category_list(',');
    } else {
    echo '' . 'Updated On ' . get_the_time($use_format) . '' . “n”;
    }
    }
    }

    add_action('thesis_hook_after_teaser_headline','add_date_to_teaser');

    Let me know if it works.

  7. Nope….getting a parse error on this one.

  8. Anything on this Ashwin?Still getting a parse error…

  9. AviD,

    I didn't manage to look at this last weekend. I will check it out today and get back to you.

    Thanks,
    Ashwin

  10. It works for me. I am wondering why it doesn't work for you…. Here is the code…

    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 if (!is_single()) {
    echo ' Updated on ' . get_the_time(get_option('date_format')) . ''.' | Posted In ' . get_the_category_list(',').'';
    } else {
    echo ' Updated on ' . get_the_time(get_option('date_format')) . '';
    }
    }
    }

    add_action('thesis_hook_byline_item', 'add_date_to_byline');

    You can find it working at:
    https://thoughtsunlimited.net/apps/sandbox/

    On Home page you see the categories – and on single post pages you don't.

    HTH. Let me know if it works.

    Thanks.

  11. Thanks so much for sandboxing it for me Ashwin! Unfortunately…still no go. Just a question though, did you remove the 30 days check function from your latest modified code?

    I think I'm just going to go with your original post code because
    A) I really like and NEED the functionality it provides.
    B) Formatting is nice but not critical.

    :-)

  12. I just made it 90 because on my sandbox site – the oldest post is in January.

    The code should work with '30' also.

  13. Hey Ashwin,
    Can you please let me know as to how do I modify the date to be displayed on the main page in a square, just like the “retweet” button.
    Thanks!

  14. Max,

    Using CSS, you'll need to give a Background color and padding to the following element, to get the date inside a square:

    .custom .headline_meta .published { … }

    Hope this helps.

  15. Max,

    Using CSS, you'll need to give a Background color and padding to the following element, to get the date inside a square:

    .custom .headline_meta .published { … }

    Hope this helps.

  16. Bradley Gauthier

    Thanks for this, exactly what I was looking for… retweeted :)

  17. Bradley Gauthier

    Thanks for this, exactly what I was looking for… retweeted :)

  18. Ashwin,
    Great post! This may be a little different subject from your post — trying to make the date “Jun 16″ with a couple of background colors — one small block and another bigger block — by the headline. For example,
    it would look like this:
    Jun 16 2nd bg color> color> Headline title here

    Not using the byline below the headline title.

    Is it doable ?? Thanks a million!

  19. Jan,

    Yes it can be done with a trick by moving the byline before the headline and having just date in it.
    But having the date within the headline… I need to check…

    Regards,
    Ashwin

  20. Ricky Henderson

    Thanks for posting this Ashwin. Is there code for Thesis that can also hide the dates of the comments on older posts?

  21. Hi Ricky,

    If you are using a plugin for comments – like Disqus etc. it is not possible.
    However if native comments are being used, then it can be possible using the hooks and code tweaks.

  22. Ricky Henderson

    Thanks Ashwin. I am using the default WordPress commenting system, however I don't have a lot experience with Thesis hooks. Could you provide a sample of code to hide old comments' dates and times similar to what you did with post dates? I would greatly appreciate it.

  23. let’s see, perhaps u could help.
    instead calculating the age, how could I ask if it’s “older than…” and the date that an admin choose??

    please, understand it’s not 30 or 90 days old!
    As an example… how to put “if it was written before January, 2010. “

  24. I did this a couple of months ago. Turns out that displaying the date on posts is one of the most important things that Google uses to determine relevancy. My site was slapped big time in Google search results because the Google crawler could not find dates on my posts older than 2 months. Yikes!

Trackbacks

  1. Ashwin says:

    New at TU: Hide Dates in Old #Wordpress Posts using Thesis Theme http://goo.gl/fb/uVv9 #thesistheme #thesistheme

    Reply
  2. Michael Davis says:

    RT @thotsunlimited: Hide Date in Old #Wordpress Posts using Thesis Theme http://bit.ly/84rAa8 #thesiswp

    Reply
  3. Ashwin says:

    Hide Dates in Old WordPress Posts using Thesis Theme http://bit.ly/521uPA

    Reply
  4. chopin_slut says:

    Nifty hack!: Hide Date in Old #Wordpress Posts using Thesis Theme http://bit.ly/84rAa8 #thesiswp (via @thotsunlimited)

    Reply
  5. Michael Davis says:

    RT @chopin_slut: Nifty hack!: Hide Date in Old #Wordpress Posts using Thesis Theme http://bit.ly/84rAa8 #thesiswp (via @thotsunlimited)

    Reply
  6. Michael Davis says:

    RT @thesisthemenet: RT @thotsunlimited: Hide Date in Old #Wordpress Posts using Thesis Theme http://bit.ly/84rAa8 #thesiswp

    Reply
  7. Lars Tong Strömberg says:

    RT @chopin_slut Nifty hack!: Hide Date in Old #Wordpress Posts using Thesis Theme http://bit.ly/84rAa8 #thesiswp (via @thotsunlimited)

    Reply
  8. Ashwin says:

    Hide Date in Old #Wordpress Posts using Thesis Theme http://bit.ly/84rAa8 #thesiswp

    Reply
  9. Tweets that mention Hide Dates in Old Wordpress Posts using Thesis Theme -- Topsy.com says:

    [...] This post was mentioned on Twitter by Ashwin, Ashwin. Ashwin said: New at TU: Hide Dates in Old #Wordpress Posts using Thesis Theme http://goo.gl/fb/uVv9 #thesistheme #thesistheme [...]

    Reply
  10. ThesisTheme.net says:

    RT @thotsunlimited: Hide Date in Old #Wordpress Posts using Thesis Theme http://bit.ly/84rAa8 #thesiswp

    Reply
  11. Ashwin says:

    Hide Dates in Old #Wordpress Posts using Thesis Theme http://bit.ly/84rAa8 #thesiswp

    Reply
  12. Michael Davis says:

    RT @thotsunlimited: Hide Dates in Old #Wordpress Posts using Thesis Theme http://bit.ly/84rAa8 #thesiswp

    Reply
  13. Mitch says:

    RT @thotsunlimited: Hide Dates in Old #Wordpress Posts using Thesis Theme http://bit.ly/84rAa8 #thesiswp

    Reply
  14. catch_down says:

    http://tinyurl.com/yhwu92b
    Hide Dates in Old WordPress Posts using Thesis Theme

    Reply
  15. Ashwin says:

    Hide Dates in Old WordPress Posts using Thesis Theme http://bit.ly/84rAa8 #thesiswp

    Reply
  16. Tweets that mention Hide Dates in Old Wordpress Posts using Thesis Theme -- Topsy.com says:

    [...] This post was mentioned on Twitter by Ashwin. Ashwin said: Hide Dates in Old WordPress Posts using Thesis Theme http://bit.ly/84rAa8 #thesiswp [...]

    Reply
  17. Christine Miller says:

    RT @bradleygauthier: anyone running thesis should add this hook: http://bit.ly/943qS5 – it eliminates dates on posts after 30 days

    Reply
  18. Bradley Gauthier says:

    anyone running thesis should add this hook: http://bit.ly/943qS5 – it eliminates dates on posts after 30 days

    Reply
  19. 27 More Customizations for the Thesis Wordpress Theme says:

    [...] Hide Dates in Old WordPress Posts Using the Thesis Theme [...]

    Reply

Leave a Reply to Pam McAllister Cancel reply

*