Automatically close comments in the Carousel view

You can use the following code to automatically close comments in the Carousel view, based on the number of days you’ve defined in Settings > Discussion:

function jpcarousel_auto_close_comments( $open, $post_id ) {
	$post = get_post( $post_id );

	$days_old = (int) get_option( 'close_comments_days_old' );

	if ( ! $days_old )
		return $open;

	if( $post->post_type == 'attachment' && time() - strtotime( $post->post_date_gmt ) > ( $days_old * DAY_IN_SECONDS ) ) {
		return false;
	}
	return $open;
}
add_filter( 'comments_open', 'jpcarousel_auto_close_comments', 10 , 2 );
This entry was posted in Code snippets, Tips & Tricks and tagged , . Bookmark the permalink.

Explore the benefits of Jetpack plans

Compare plans in detail to see how Jetpack can help you design, market, and secure your WordPress site.

Compare plans

Have a question about this article?

Comments are currently closed for this article, but rest assured we're still here to help! Send us a message and we'll get back to you.

Contact us
  • Enter your email address to follow this blog and receive news and updates from Jetpack!

    Join 103,748 other followers

  • Our most popular posts

  • Browse by topic

  • %d bloggers like this: