[Resolved] Only show published and updated dates if the post is 6 months old or younger

Home Forums Support [Resolved] Only show published and updated dates if the post is 6 months old or younger

Home Forums Support Only show published and updated dates if the post is 6 months old or younger

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1995599
    Simon

    I want to show the published (or updated) date below the post (I already opened a topic for that here: https://generatepress.com/forums/topic/show-the-date-at-the-end-of-the-post/ ).

    Now I want to only show this date if the post is not older than 6 months. Is there a way to do this?

    #1995891
    David
    Staff
    Customer Support

    Hi there,

    Try adding this PHP Snippet:

    add_filter( 'generate_post_date_output', function($post_date){
        if( get_the_time( 'U' ) < strtotime('-180 days') ) {
            return null;
        }
        return $post_date;
    },15,2);
    #1995900
    Simon

    works perfectly! thank you

    #1996072
    David
    Staff
    Customer Support

    Glad to heat that!

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.