How To Disable Comments On More Than X Days Old Posts In WordPress Blog

Posted by


Many wordpress users wants to disable comments on posts which are older than x days. There is an inbuilt function in wordpress. For that you need to follow these procedure:

1_ Login into wordpress admin area
2. Go to settings -> discussion settings
3. There is an option ‘Automatically close comments on articles older than X Days’. Set your desired days here to disable comment [view this screen capture].


Also an other way to do it. For that you need to deal with the code part of the wordpress theme files. To enable auto comment closing, you need to add this code in functions.php file from your theme:

function close_comments( $posts ) {
if ( !is_single() ) { return $posts; }
if ( time() – strtotime( $posts[0]->post_date_gmt ) > ( X * 24 * 60 * 60 ) ) {
$posts[0]->comment_status = ‘closed’;
$posts[0]->ping_status = ‘closed’;
return $posts;
add_filter( ‘the_posts’, ‘close_comments’ );

You can easily change the number of days after posts can not be commented by changing the X with your desired days on line 3 of the close_comments() function.

That’s ot!


Shane G.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.