Have a Question?
Extra Fields for WP Comments
Hook: comment_form
The comment for is named comment_form. As part of the core, this function has many hooks to customize the form’s contents.
We’re going to use a few of those hooks: comment_form_logged_in_after and comment_form_after_fields. They will add something after the “You’re logged in as…” message or the name, email and website fields respectively.
We’ll just call add_action for each of our hooks and in our hooked function spit out form code we want.
<?php add_action(‘comment_form_logged_in_after’,‘pmg_comment_tut_fields’); add_action(‘comment_form_after_fields’,‘pmg_comment_tut_fields’); functionpmg_comment_tut_fields() { ?> <pclass=“comment-form-title”> <label for=“pmg_comment_title”><?php_e(‘Title’);?></label> <input type=“text”name=“pmg_comment_title”id=“pmg_comment_title”/> </p> <?php }
Depending on the them imstalled, the form can be beautified:
<?php
add_action(‘wp_head’,‘pmg_comment_tut_style_cheater’);
functionpmg_comment_tut_style_cheater()
{
?>
<style type=”text/css”>
#respond .comment-form-title {
position:relative;
}
#respond .comment-form-title label {
background:#EEE;
-webkit-box-shadow:1px2px2pxrgba(204,204,204,0.8);
-moz-box-shadow:1px2px2pxrgba(204,204,204,0.8);
box-shadow:1px2px2pxrgba(204,204,204,0.8);
color:#555;
display:inline-block;
font-size:13px;
left:4px;
min-width:60px;
padding:4px10px;
position:relative;
top:40px;
z-index:1;
}
</style>
<?php
}