I’m currently developing a custom theme from scratch.
In the past week, I’ve been trying to change the order of the HTML elements output by the comment_form()
.
I basically don’t know any PHP, and I was unable to find information on the comment_form()
that successfully covers how to rearrange the layout of its output, including the WordPress Codex.
Can anyone please explain how to rearrange the elements outputted by the comment_form()
, preferably without having to be proficient in PHP and the inner workings of WordPress?
Please don’t provide solutions that rely on re-positioning elements with CSS; this can’t be the way you’re intended to customize the output.
If it turns out there isn’t an optimal way to achieve this, would it then be possible to customize comments.php
without using the comment_form()
, like you would before the function was introduced?
The following links cover some of the most relevant methods I’ve tried. They either don’t work at all or don’t achieve the correct result:
http://freetexthost.com/wplcq61i3d
(Sorry, but I’m not allowed to post more than two links directly in the post.)
Thank you.
Re-arranging the comment fields
The comment text area has been moved to the top in WordPress 4.4:
What if we prefer the old setup, where it was at the bottom?
Re-arranging the
author
,url
andemail
comment fieldsWe can modify the display order, of the author, url and email fields, with:
but we will have to find another approach to re-order the comment text area an the submit button.
Custom Workaround
To re-arrange all five comment fields, we can use the custom
wpse_comment_fields
filter:in the
functions.php
file or in a plugin.Example:
Author
field at topLet’s move the author field to the top:
The comment form will then display as:
Example:
Comment
field at the bottom and remove theUrl
fieldHere we display the comment field at the bottom and remove the url field:
Then the comment form will show:
Demo Plugin
Here’s our demo plugin that supports the
wpse_comment_fields
filter (PHP 5.4+):