Hide Dates in Old WordPress Posts using Thesis Theme

by Ashwin

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

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  • http://twitter.com/thotsunlimited/status/7545824682 Ashwin

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

  • http://twitter.com/web2feed/status/7547065677 Michael Davis

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

  • http://twitter.com/tublogger/status/7551727285 Ashwin

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

  • http://twitter.com/chopin_slut/status/7557094336 chopin_slut

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

  • http://twitter.com/web2feed/status/7557227288 Michael Davis

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

  • http://twitter.com/web2feed/status/7557916185 Michael Davis

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

  • http://twitter.com/tongstromberg/status/7558106556 Lars Tong Strömberg

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

  • http://twitter.com/thotsunlimited/status/7546928625 Ashwin

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

  • http://topsy.com/tb/bit.ly/84rAa8 Tweets that mention Hide Dates in Old Wordpress Posts using Thesis Theme — Topsy.com

    [...] 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 [...]

  • http://twitter.com/thesisthemenet/status/7557905133 ThesisTheme.net

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

  • http://twitter.com/thotsunlimited/status/8397072412 Ashwin

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

  • http://twitter.com/web2feed/status/8397142408 Michael Davis

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

  • http://twitter.com/theworkingdad/status/8398144079 Mitch

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

  • http://twitter.com/catch_down/status/8530221376 catch_down

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

  • http://pammcallister.com Pam McAllister

    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!

  • https://thoughtsunlimited.net/blog Ashwin / Thoughts Unlimited

    Pam,

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

  • manavecplan

    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

  • https://thoughtsunlimited.net/blog Ashwin / Thoughts Unlimited

    Hey AviD,

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

    Regards,
    Ashwin

  • manavecplan

    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');

  • https://thoughtsunlimited.net/blog Ashwin / Thoughts Unlimited

    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.

  • manavecplan

    Nope….getting a parse error on this one.

  • manavecplan

    Anything on this Ashwin?Still getting a parse error…

  • https://thoughtsunlimited.net/blog Ashwin / Thoughts Unlimited

    AviD,

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

    Thanks,
    Ashwin

  • https://thoughtsunlimited.net/blog Ashwin / Thoughts Unlimited

    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.

  • manavecplan

    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.

    :-)

  • https://thoughtsunlimited.net/blog Ashwin / Thoughts Unlimited

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

    The code should work with '30' also.

  • http://www.pentestit.com Max

    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!

  • http://www.powerwebbusiness.com/ Ashwin

    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.

  • http://twitter.com/thotsunlimited/status/13607988419 Ashwin

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

  • http://www.powerwebbusiness.com/ Ashwin

    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.

  • http://topsy.com/trackback?utm_source=pingback&utm_campaign=L1&url=https://thoughtsunlimited.net/blog/wordpress/hide-dates-in-old-thesis-theme-posts/ Tweets that mention Hide Dates in Old Wordpress Posts using Thesis Theme — Topsy.com

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

  • http://twitter.com/christinerobyn/status/14004398971 Christine Miller

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

  • http://twitter.com/bradleygauthier/status/14004194374 Bradley Gauthier

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

  • http://www.bradleygauthier.com Bradley Gauthier

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

  • http://www.bradleygauthier.com Bradley Gauthier

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

  • http://consolidationsupport.com/wordpress/ Jan

    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!

  • http://www.powerwebbusiness.com/ Ashwin

    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

  • http://themethesis.com/tutorials/27-more-customizations-for-the-thesis-theme/ 27 More Customizations for the Thesis Wordpress Theme

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

  • http://twitter.com/RickyHenderson Ricky Henderson

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

  • http://www.powerwebbusiness.com/ Ashwin

    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.

  • http://twitter.com/RickyHenderson 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.

blog comments powered by Disqus

Previous post:

Next post: