Make A Modal Comment Window in WordPress

For those maintaining WordPress blogs with regular posts, one of the most frustrating things can be getting users to comment regularly. Obviously we want to make this as easy as possible for them. Sure there’s the #comments anchor that we can link to after they’ve read the article that jumps to the bottom of the article’s page, but why reload the article? Let’s let them comment in-page!

For an example, go to Civitas Review and click on a speech bubble beside a post title.

You might think this would be a massive undertaking. Luckily, WordPress makes this very easy for us. A little-used core feature is comments_popup_link(), which in conjunction with comments_popup_script(), generates a bit of Javascript to open a stripped-down comment form in a new window.

So if your theme has a comments-popup.php, most of your work is already done! All we need to do is make it a modal.

  1. First thing you need is Jquery. Check your WordPress header output for it, because a lot of plugins use it already. If you already have it in your head, you can skip this step.
  2. You’ll also need a modal plugin. For our purposes, NyroModal is our best bet, because it can take whole pages (and not just images) as modal content.
  3. Make sure both Jquery and NyroModal are called in your WordPress header, like so: <script type="text/javascript" src="path/to/your/js/nyroModal.js"></script> Same for Jquery, before the NyroModal script.
  4. Almost done. NyroModal is built so that if you give any link the class “nyroModal”, it will open in a modal window. The third argument of comments_popup_link is the link class, so we just need to insert the function in our theme like so: comments_popup_link('No comments', 'One comment', '% comments', 'nyroModal')

That’s it! Now style your comments-popup.php to your liking, and you have a nice modal comments window.

About »

Hey, I'm C. Harwick, a web designer, musician and blogger living in Raleigh, where I work at a think tank.

Care to know more? Read on »

Twitter »

Feb
05
5:39
Spammer on the blog: "Last year I had the emergency exit row at the window ALL BY MYSELF. Now that was mega-awesome!" #coolstorybro
Feb
05
4:31
Update to an old post: In what sense does God act? Divine #praxeology, now with 20% more Augustine. http://t.co/ZLCX75ZP

RSS »

Design By Thrica Powered By Wordpress Hosted By Nearlyfreespeech Licensed under a Creative Commons Attribution 3.0 License
Veritas Pulchritudo Est