Controlling where the reply goes in your WordPress theme

Here is another nice quick tip for you WordPress fans. I found through some research that it is quite easy to tell WordPress where your comments reply section should go. If you take at one of the comments on my site and hit reply, your reply falls below the comment border like this:
ericlightbodydotcom comments reply.jpg
I really don’t care for the separation, and wanted something more like Chris does over at css-tricks.com
css-tricksdotcom comments reply.jpg
It turns out that this is actually quite easy, but took me some time to find out.

If you have a blog that is supporting comment replies, then in all likelihood you’ll see the function comment_reply_link in your functions.php file. In my case, I use Ian Stewart’s awesome comments template and all of that is already taken care of for me when I create new WordPress themes. In the WordPress documentation for the function, they mention the add_below parameter. That’s exactly what we need. Simply put the id of the html element you would like it to fall after. WordPress tacks on the post id # so that the reply form falls under the correct comment. In my case, I have one of my comments wrapped like:

So, my comment_reply_link looks something like this:

if ($args['type'] == 'all' || get_comment_type() == 'comment') {
	comment_reply_link(
		array_merge(
			$args, array(
			'reply_text' => __('Reply', 'shape'),
			'login_text' => __('Log in to reply.', 'shape'),
			'depth'      => $depth,
			'before'     => '',
			'add_below'  => 'div-comment',
		)));
}

Post a Comment

I promise not to publish your email address.

*
*