More
    Home Design / Dev Disable Comments and Pingbacks in Old Posts

    Disable Comments and Pingbacks in Old Posts

    Somehow after a period of long time, we still receiving comments and trackbacks for our old wordpress posts. This maybe troublesome for us to approve if it is require moderation and moreover if they are likely more to spams and hot-linking only. However, the is an easy hack where you can disable comments and trackbacks after certain a period the post was published.

    Simply open your wordpress theme’s functions.php using any of your favorite editor and add this code below:

    [sourcecode language=’php’]

    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’ );
    ?>

    [/sourcecode]

    You can run this script as a plugin, through your theme’s functions.php, or through a custom user-functions.php file. Simply set the desired number of days by changing the number “30” to whatever you would like. As is, this script will close comments, pingbacks and trackbacks on all articles posted more than 30 days ago.

    WPTidBitshttps://wptidbits.com/
    Owner of WPTidBits. Totally in love with WordPress!

    LEAVE A REPLY

    Please enter your comment!
    Please enter your name here

    110FansLike
    761FollowersFollow

    You May Also Like