How to Enable Threaded Comments in WordPress

Home » Snippets » How to Enable Threaded Comments in WordPress
0

Created with:

Visibility: 

public

Creator: WPTurbo Team

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project

Are you looking to add threaded comments to your WordPress site? Threaded comments are a great way to encourage engagement and discussion among your readers. Fortunately, enabling threaded comments in WordPress is a quick and easy process. In this article, we’ll show you how to do it in just a few simple steps.

					function wpturbo_enable_threaded_comments() {
    if ( is_singular() && comments_open() && ( get_option( 'thread_comments' ) == 1 ) ) {
        wp_enqueue_script( 'comment-reply' );
    }
}
add_action( 'wp_enqueue_scripts', 'wpturbo_enable_threaded_comments' );
				

In this article, we will discuss how to enable threaded comments in WordPress. Threaded comments allow for a more organized and easier-to-follow conversation in the comments section of your blog. Fortunately, WordPress makes enabling threaded comments easy by allowing you to tweak a few settings in your WordPress dashboard and by adding a little bit of code to your functions.php file.

The above code snippet does just that. The first line of the function named wpturbo_enable_threaded_comments() checks if the current page is a singular page or a single post page by using the is_singular() function. This ensures that the code only runs on posts or pages that are meant to have comments. The ( comments_open() ) checks whether comments are enabled on the current post or page, and finally, ( get_option( 'thread_comments' ) == 1 ) checks whether threaded comments are enabled by checking the option set in the WordPress dashboard. If all of these conditions are met, the code injects the comment-reply.js script by calling the wp_enqueue_script() function.

Enabling threaded comments is now as simple as copying and pasting the above code snippet into your functions.php file or modifying an existing functions.php file if one exists. Results should be seen immediately after refreshing the post page.

Register an account to save your snippets or go Pro to get more features.