Disable comments on posts over one month

Stockholm WordPress Theme Review

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.

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

Comments  Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!