Home / comment / Disable comments on posts over one month
  • How to Disable comments on posts over one month

    disable-comments-on-old-posts

    In a number of project I have had to disable comments after a month or x period of time, this little snippet will let you disable comments on posts older than one month. Just add this great little snippet to the functions.php of your wordpress theme and you are ready to go.

    ( click code to copy )

    wordpress snippet : PHP

    <>
    <?php
    		function close_comments( $posts ) {
    			if ( !is_single() ) { return $posts; }
    			if ( time() - strtotime( $posts[0]->post_date_gmt ) > ( 30 * 24 * 60 * 60 ) ) {
    			$posts[0]->comment_status = 'closed';
    			$posts[0]->ping_status    = 'closed';
    			}
    		return $posts;
    		}
    		add_filter( 'the_posts', 'close_comments' );
    		?>
    

    ( WordPress codex functions, hooks, in this snippet. )

    the_posts, is_single, the_post, add_filter,