Disable Comments on 30-day older posts
Hi! I have a new function for you :) That one about commenting and automatically closing comments. We can disable commenting on posts older then 30 days. We will change functions.php. Be careful please.
With this function/recipe you will change your functions.php file located in your theme folder. If you have no information about WordPress coding -so you’re a newbie- you can get some support if you send a mail to me. Don’t touch your functions.php if you don’t know about WordPress
For disable commenting we have to make changes in functions.php in our theme folder. First, you have to make a backup for this file. After backup open your functions.php with your favourite php editor and add code to here.
Here is th code;
< ?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' );
?>
The 30 is day. If you change this value you can change disabling time.
That’s All! Have a nice day!
- Wordpress















Made by Symmetric Web
Distributed by Smashing Magazine
No comments yet!