The comment_form_after_fields WordPress PHP action fires after the comment fields in the comment form, excluding the textarea.
Usage
add_action('comment_form_after_fields', 'your_custom_function'); function your_custom_function() { // your custom code here }
Parameters
- None
More information
See WordPress Developer Resources: comment_form_after_fields
Examples
Adding a custom checkbox to the comment form
This example adds a custom checkbox to the comment form after the default fields.
add_action('comment_form_after_fields', 'add_custom_checkbox'); function add_custom_checkbox() { echo '<p><input type="checkbox" name="custom_checkbox" id="custom_checkbox" value="1" /> <label for="custom_checkbox">I agree to the terms and conditions</label></p>'; }
Adding a notice after comment fields
Add a notice after the comment fields to inform users about the comment moderation policy.
add_action('comment_form_after_fields', 'add_comment_notice'); function add_comment_notice() { echo '<p><strong>Note:</strong> All comments are moderated before publication.</p>'; }
Adding a privacy policy link
Display a privacy policy link after the comment fields.
add_action('comment_form_after_fields', 'add_privacy_policy_link'); function add_privacy_policy_link() { echo '<p>By submitting a comment, you agree to our <a href="/privacy-policy">Privacy Policy</a>.</p>'; }
Adding social media sharing buttons
Add social media sharing buttons after the comment fields.
add_action('comment_form_after_fields', 'add_social_sharing_buttons'); function add_social_sharing_buttons() { echo '<div class="social-sharing"><a href="http://www.facebook.com/sharer.php">Share on Facebook</a> | <a href="http://twitter.com/share">Share on Twitter</a></div>'; }