[Resolved] How to completly hide the date on old posts

Home Forums Support [Resolved] How to completly hide the date on old posts

Home Forums Support How to completly hide the date on old posts

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #246567
    Patrick

    Hello Tom,
    I know I can Hide the post date from post in the customizer. That works fine for all posts, but I would like to hide the date only from posts that are like two years old.

    I have the plugin wp old post date remover which works fine by hiding the date for the user (through css), but still google sees the date.

    Perhaps it would help if i knew what filter, acton etc is jused by the customizer to remove the date, then i could perhaps make the old post date remover plugin use that.

    Thank you

    #246726
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Not sure it will work, but you could try something like this:

    add_filter( 'generate_post_date','tu_hide_old_post_dates' );
    function tu_hide_old_post_dates()
    {
    	global $post;
    	if( strtotime( $post->post_date ) < strtotime('-730 days') ) {
    		return false;
    	}
    	
    	return true;
    }

    Adding PHP: https://generatepress.com/knowledgebase/adding-php-functions/

    Let me know ๐Ÿ™‚

    #246911
    Patrick

    Thank you Tom,
    it seems to work great in my functions.php

    #247008
    Tom
    Lead Developer
    Lead Developer

    You’re welcome ๐Ÿ™‚

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