I’m a huge fan of the commenting improvements introduced in Wordpress 2.7. It’s been a tremendous boon to have first-class threaded commenting features right out of the box.
However, one thing I’ve never understood is the decision to use an anchor element to cancel an open reply box. I’m far more accustomed to the reddit style of placing a cancel button next to the submit button, like this:

The problem with the anchor element generated by Wordpress is that it looks really out of place when arranged next to the “submit comment” button. I had hoped there would be a parameter to change the anchor element into a button, but was disappointed to find that this particular HTML is hardcoded into the get_cancel_comment_reply_link() function.
However, the function does provide a filter hook, which I’ve used to make the change I desired. I simply intercept the HTML and return my own version with a button. It’s not very elegant, but it works.
If you’d like to use this hack, just add the following code to your theme’s functions.php file:
/** * Use an HTML button element for the cancel comment reply link. */ function cancel_comment_reply_button($html, $link, $text) { $style = isset($_GET['replytocom']) ? '' : ' style="display:none;"'; $button = '<button id="cancel-comment-reply-link"' . $style . '>'; return $button . $text . '</button>'; } add_action('cancel_comment_reply_link', 'cancel_comment_reply_button', 10, 3);
9 Comments
Related posts:
- saidit, a Greasemonkey script for reddit: View and install the saidit Greasemonkey script on userscripts.org. Click here » The saidit script enhances reddit comment pages by...
- On clickable gradient effects using CSS: Alternatively, how to overlay an image on top of an element without interfering with clickable links underneath: How to makean...
- Haskell “gem” logo: Yesterday, I posted my first try on the Haskell logo contest. Here’s my second logo: For me, this logo emphasizes...
- Socialite on AMO: As of approximately 7:08 am, Socialite is now publicly available on AMO (addons.mozilla.org). It’s been a long time coming, and...

Thanks for posting this. I tried it out on my template (editing the Default Kubrick in 2.8.4) and it worked. I hacked your code further to change the button label name:
return $button . $text= ‘Cancel Comment’ . ”;
The only glitch with this code is that the button appears in a post all the time. It only disappears when you click on a threaded reply and then cancel.
I’m not a PHP or WP expert but somewhere there’s something missing in the code. The Cancel button should only appear when replying to a threaded comment right?
Anyway, great work!
Oops! You are correct. There was something missing. The second line of
cancel_comment_reply_buttonoriginally read:Note that this doesn’t make use of the
$stylevariable that was set on the first line. The$stylevariable contains CSS that hides the button if it is not a comment reply — the behavior you were missing!I checked my
functions.phpfile, and sure enough, here was the correct line:Good eye. Thanks for pointing this out. I’ve amended the original post.
Awesome! It works like a charm! Hey…thanks for fixing this so fast!
Keep up the excellent work!
BTW… What code did you use to get the Cancel button down next to the Submit Comment button? My button still hangs under the form title where the link used to be. Did you use CSS?
Any help would be appreciated.
Check the location of the call to
cancel_comment_reply_link()in yourcomments.phpfile. I moved it to be inside a paragraph with the submit button, like this:You might also consider setting the label for the button as a parameter here, rather than hard-coding it into your
functions.php.Thanks! I was just coming back here to comment that I figured it out and saw your post. And you filled in the blanks for me too. I found the
Anyway, your code puts order back into the WP Comments GUI!
cancel_comment_reply_link()and moved into thenext to the Submit button. Now it all looks fantastic! I don’t understand what made the WP team lay this form out so oddly to begin with.Thanks for pointing out a better way of labeling the button. Gettin’ it out of the functions.php file right now.
Thanks again
Here’s a reason to do it the way WP does: http://www.codinghorror.com/blog/2010/03/the-opposite-of-fitts-law.html
Nice that you can change it if you don’t like it of course, thanks for figuring out that hack. Could do the same thing to make it a button but move it out of the way or style it a bit differently or whatever.
You have to decide about the role and importance of cancel for a particular site and commenting community I guess. It’s always worth thinking about whether a post you’re making is a good contribution and cancelling it if not.
The normal link for cancel makes sense to denote that this is not the primary action. The latter in turn has a real button. So from a usability and persuasive design standpoint, everything had been well.
There’s actually a good reason for the cancel button to not be a button, see this Coding Horror post:
http://www.codinghorror.com/blog/2010/03/the-opposite-of-fitts-law.html
Basically the reason might be that they don’t want you hitting the ‘cancel’ button by mistake, when you’re looking to hit a similarly styled ’submit’ or ‘ok’ button.