To customize the built-in WordPress comments form you could use plugins, but those often slow down your site. A better approach to add custom content to the comments form is by using the WordPress comments form hooks.
List of WordPress Comments Form Hooks
There are seven WordPress comments hooks. Some of them are not available depending the discussion settings (learn more).
- comment_form_before
- comment_form_top
- comment_form_before_fields
- comment_form_after_fields
- comment_form
- comment_form_must_log_in_after
- comment_form_after
The hooks speak for themselves, but for more comprehensive look see the WordPress Comments Form – Visual Hook Guide.
PHP Snippet: Add custom content above the WordPress comments fields
Lets see how to add our custom content ‘comment policy text’ above the comment fields. To place the content there we’ll use comment_form_top hook.
add_action('comment_form_top', 'webroom_add_comment_notice');
function webroom_add_comment_notice() {
echo '<p>Comment policy: All comments are manually moderated and those deemed to be spam or promotional will be deleted.</p>';
}
PHP Snippet: Add custom content below the WordPress comments fields
Lets see how to add our custom content ‘comment policy text’ below the comment fields and above the Post comment button. To place the content there we’ll use comment_form_after_fields hook.
add_action('comment_form_after_fields', 'webroom_add_comment_notice');
function webroom_add_comment_notice() {
echo '<p>Comment policy: All comments are manually moderated and those deemed to be spam or promotional will be deleted.</p>';
}
PHP Snippet: Add custom content below the Post comment button in WordPress comments
Lets see how to add our custom content ‘comment policy text’ below the comment fields and above the Post comment button. To place the content there we’ll use comment_form_after hook.
add_action('comment_form_after', 'webroom_add_comment_notice');
function webroom_add_comment_notice() {
echo '<p>Comment policy: All comments are manually moderated and those deemed to be spam or promotional will be deleted.</p>';
}
Note that depending the WordPress discussion settings you have some hooks are not available. For example if only logged in users can comment or the comments are disabled for particular post. Learn which WordPress comments form hooks are active depending the settings you have in the WordPress Comments Visual Hooks Guide.
Learn more about Comments in WordPress in the official documentation.
To customize the built-in WordPress comments form you could use plugins, but those often slow down your site. A better approach to add custom content to the comments form is by using the WordPress comments form hooks.
List of WordPress Comments Form Hooks
There are seven WordPress comments hooks. Some of them are not available depending the discussion settings (learn more).
The hooks speak for themselves, but for more comprehensive look see the WordPress Comments Form – Visual Hook Guide.
PHP Snippet: Add custom content above the WordPress comments fields
Lets see how to add our custom content ‘comment policy text’ above the comment fields. To place the content there we’ll use comment_form_top hook.
PHP Snippet: Add custom content below the WordPress comments fields
Lets see how to add our custom content ‘comment policy text’ below the comment fields and above the Post comment button. To place the content there we’ll use comment_form_after_fields hook.
PHP Snippet: Add custom content below the Post comment button in WordPress comments
Lets see how to add our custom content ‘comment policy text’ below the comment fields and above the Post comment button. To place the content there we’ll use comment_form_after hook.
Note that depending the WordPress discussion settings you have some hooks are not available. For example if only logged in users can comment or the comments are disabled for particular post. Learn which WordPress comments form hooks are active depending the settings you have in the WordPress Comments Visual Hooks Guide.
Learn more about Comments in WordPress in the official documentation.
Recent Articles
Get
Professional WordPress Speed Optimization Service
Related Articles
If you enjoyed reading this, then please explore our other articles below:
Level Up Your Website with a Skilled WordPress Developer: Unleash its Full Potential
How to redirect to “All Posts” after post update or publish in Block Editor
Top Emerging Web Development Trends in 2022/2023
How to Publish a Plugin to the WordPress Plugin Directory
Top 3 Tips to Migrate from Wix to WordPress
7 Ideas to Monetize a Website and Increase Your Income
How to display subcategories in Category pages in WordPress
What is WebP and how to speed up WordPress by reducing the size of photos by up to 35%