Join 9,000+ Readers

Setup Ajax Comments Pages in WordPress

by Jake Rocheleau

on June 9, 2013

in Wordpress

It is strange to see how WordPress hasn’t adopted Ajax comments for blog posts. Obviously the system should be built to handle typical PHP requests, and you can always add the Ajax functionality on the frontend. But it does make the process of writing your own custom functions a lot more difficult. Thankfully there are a number of open source choices which you may quickly install and get working on any WordPress-based website.

For this article I would like to focus on ajax comments pages when displaying many discussion posts. WordPress will automatically paginate comments listings beyond a certain number. You can adjust this value in the WP admin area, but the comments pages will always load a new permalink. Google and other crawlers will like this structure but the user experience leaves room for improvement. I hope to share a few resources for helping developers come to terms with Ajax paginated comments.

AJAX Comment Loading

My first plugin of choice is named Ajax Comment Loading. As you may insinuate from the name, this plugin will load all of your page comments through a separate AJAX request. Namely this includes the default page/post comments along with all the other comment pages. It will help to improve page speed because the loading process has been split.

comment loading ajax pagination website plugin open source

Notably when you first load a blog post WordPress will only pull templates up until the comment form. This plugin will skip all the user comments entirely, allowing your full page to load without comments(at first). Then Ajax requests will pull the user comments and comment pages into view. The installation process requires simply activating the plugin and letting it work. This code was structured around the Twenty Ten theme of comment display, so you might want to edit your own theme to match a similar ID/class system. But otherwise this plugin has been an exceptional choice for loading paginated user comments.

WP Comment Master

General all-around comments may be edited and critiqued by using this plugin. WP Comment Master is also a free download and install for your website. The features include both ajax comment posting and loading ajax comment pages. But the best part is how all the HTML has been written with semantics in mind.

You can still find all the permalinks to each page stored into the anchor links. This means Google and similar web crawlers will be able to locate your comment pagination and still view the results. Only end users will benefit from the Ajax effects. Plus multiple WordPress users have tested this plugin over a variety of themes, and it does appear to be very stable. You can view a live demo from this blog post using the WP Comment Master plugin.

plugins pagination ajax loading open source wp

Silk AJAX Comments

The release of Silk Ajax Comments was only in July of 2012, so this is a newer plugin to the repository. But as of this article’s publication the repo has a complete set of 5-star reviews from seven different WordPress users. Silk comments will stop the normal wp-comments-post.php file from handling all of the data submission. Instead it will be handled via Ajax and the page does not need to be refreshed.

silk ajax comments plugin wordpress open source

Similarly you will notice the user error messages have been redirected without reloading. I think this is even more useful because readers who want to share a comment will take their time writing out a response. When a user submits their comment only to be shown an error on a new page, they might as well just leave right away. Not everybody will go back and take the time to edit their response unless it is very important. Silk is a great plugin for handling this method of user feedback and dynamic error messages.

Yet Another Ajax Paged Comments

Although the original developer has not updated this plugin for a couple of years, I still think the codebase is good enough for testing. I have seen YAAPC plugin but never actually tested in my own website. Actually I have been very surprised at the large support for pagination through ajax, especially for user comments. WordPress developers do like to build these things and release them on the website for free.

From the plugin’s webpage you will notice this version does include a substantial number of features. We can tell the SEO is already written to include multiple pagination links. Additionally you will find meta options for nofollow and dofollow in the plugin settings panel. You can even set the crawler options to not index further comments pages! Definitely a more detailed solution for WordPress users who don’t want to get their hands dirty in backend PHP code. The only problem is that if you run into an issue, very little support is available. YAAPC plugin is worth testing but it may not be the greatest solution for every website.

Final Thoughts

You can most likely comb through the WordPress plugin repository and find a wide assortment of similar resources. I have attempted to showcase options which are easiest to setup and also offer an extensive array of administration options. Creating your own custom Ajax JS file along with backend PHP functionality would be a more detailed method, albeit a lot harder to manage. Check out some of the resources listed in this post and feel free to share your own ideas in the discussion area below.

About Jake Rocheleau

Jake is a freelance writer and web developer. He writes articles for numerous blogs on freelancing, Wordpress, CSS3, and jQuery. You can find him all throughout Google and follow his tweets @jakerocheleau. Connect with Jake on Google +