I am trying to customise the output code of
<?php comment_form(); ?>
At the moment the submit button outputs the following:
<p class="form-submit">
<input name="submit" type="submit" id="submit" value="Post Comment">
<input type="hidden" name="comment_post_ID" value="486" id="comment_post_ID">
<input type="hidden" name="comment_parent" id="comment_parent" value="0">
</p>
I would like it to output the following:
<div class="darkbutton" onclick="document.commentform.submit()">
<span class="darkbutton-left"></span><a href="javascript: submitform()">Log In</a>
<span class="darkbutton-right"></span>
</div>
so as the completely restyle the button. Now I know it could be done by editing the core WordPress files in comment-template.php but I really don’t want to have to do this if there is any other way.
Any suggestions greatly appreciated! 🙂
Have a trick
You can following after
I needed to add a class to form tag and the submit button. I don’t know where I found it, but this solution helped me out. You have to modify the str_replace to suite your needs.
Wrodpress has “Pluggable Functions” That allow you to overwrite some core functions. This is useful because they won’t overwrite your changes when upgrading and such. However, it does not look like the
comment_form()
is one of them.If you’re looking to avoid modifying core files, why not just edit your template file to output your desired code instead of calling the
comment_form()
function? Otherwise, I’m pretty sure you’re just going to have to modify that file.You can read some discussion about this issue here, but it doesn’t look like any fixes have been made to the WP codebase.
For now, I’m making style changes to my button on client side with jQuery. You could generate your
<div>
block with jQuery, and then hide theirform-submit
block by doing this:This isn’t foolproof code, but it’s a hack that will work until they implement something better.