Follow Brian Li (@DecryptoBL) on Twitter.
Follow Brian Li (@bwhli) on Instagram.

Force Disqus to Load on the Last Page of a WordPress Post

February 4, 2015

Splitting long posts into multiple pages is a great way to speed up load times and reduce bounce rate. If you’re using the Disqus commenting system on your site, it loads on every page of a multi-page post by default. This isn’t ideal because you always want your visitors to finish reading a post before commenting. In this tutorial, I’m going to show you how to force Disqus comments to load only on the last page of a paginated WordPress post.

The first thing you need to do is install Disqus Conditional Load, a free WordPress plugin that lets you customize Disqus’ behavior. The installation process is pretty self-explanatory, but click here if you need help setting it up. The next few steps will require you to log into your server via FTP, and edit some code. In this tutorial, I’ll be using two highly recommended apps – Transmit and Sublime Text.

Login to your server, and navigate to /wp-content/plugins/disqus-conditional-load/includes.

disqus-conditional-load-includes-folder

  • The file you need to edit is js-comments.php, so download that to your desktop or edit it in your FTP app if that’s supported. Hit enter at the end of Line 10, and paste this code into the now empty Line 11.global $multipage, $numpages, $page;
    if(( $multipage && $page == $numpages ) || (!$multipage)) {
  • Now add another closing curly brace at Line 24, so it looks like this: <?php }} ?>
  • Save and upload the edited file.

At this point, Disqus should only load on the last page of a multi-page WordPress post. If you don’t feel comfortable messing around with code, you can download an edited version of js-comments.php here. Feel free to leave a comment below if you have any questions or concerns.


Questions?

Find me on Twitter, or send me an email.