Sticky Comments on Top in WordPress

How to make comments ‘sticky’ in WordPress

There is a WordPress plugin named “Sticky Comments” to set comments “sticky” but it seems that it no longer works.

I implemented this feature by combining a plugin and a simple jQuery code.

1. First, please install “Featured Comments” and activate it. Now you can add add “featured” or “buried” css class to selected comments, which enables you to highlight comments that add value to your post.

2. Now, it’s time to hook a js file.

Please copy the jQuery code at http://jsfiddle.net/bcbxftr6/107/ and save it as a js file (e.g. stickycomments.js.) Now you need to enqueue this js file by referring to this WordPress codex page. For example, I added the following code to my theme’s function file (functions.php):

function iconicchild_scripts() {
wp_enqueue_script( 'wpb_kboardviewcomment', get_stylesheet_directory_uri() . '/js/stickycomments.js', array('jquery'), '20150429', true );
}
add_action( 'wp_enqueue_scripts', 'iconicchild_scripts' );

3. Now, please add the following line to your theme’s comments file (comments.php):

<div class="featuredcomments left"><span class="featuredon"><i class="fa fa-square-o" style="margin-right:2px;"> Sticky Comments on Top</span><span class="featuredoff"><i class="fa fa-check-square-o">i> Sticky Comments on Top</span></div>

comments file in WordPress to make comments sticky

The Awesome font must be installed to display the icons (“-square-o”>” and “<i class=”fa fa-check-square-o”>”) correctly. You can replace them with your own icons.

Now, the comments set to “featured” using the Featured Comments plugin will be placed on top of the comments list when loading a page/post. (The text “Sticky Comments on Top” works as a toggle link.) If you want that the featured comments are not sorted when loading a page or a post, please use jQuery code at http://jsfiddle.net/bcbxftr6/113/.

Sticky Comments on Top in WordPress

 

Please feel free to leave a Comment (). Have a great day.