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.
How to add custom content to the WordPress comments form
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
Related Articles
If you enjoyed reading this, then please explore our other articles below:
Maximizing Sales with Eye-Catching Banner Images in WooCommerce
December 20th, 2024|eCommerce, WooCommerce|
Boost Your WooCommerce Store with Automated Two-Way Up-Sell Links
May 7th, 2024|eCommerce, WooCommerce|
The Role of UX Principles in Crafting a Winning WooCommerce Store
March 18th, 2024|WordPress, WooCommerce|
Add class to menu item if product category is empty
March 15th, 2024|WordPress, WooCommerce|
Exploring WooCommerce Alternatives for WordPress: A Comprehensive Comparison
February 27th, 2024|WordPress, Plugins, WooCommerce|
Maximizing Sales: The Best Free Abandoned Cart Recovery Plugins and Email Services for Your eCommerce Business
February 26th, 2024|WordPress, eCommerce, Marketing, Plugins, WooCommerce|
How WordPress Development Services Can Transform Your Website
5 Worst WordPress Mistakes to Avoid During Development
What is Headless WordPress
Understanding Cron Jobs: Definitions and Examples
WordPress Security: Best Practices for Protecting Your Website in 2024
A Comprehensive Guide to WordPress Multilingual Websites
The Role of UX Principles in Crafting a Winning WooCommerce Store
Add class to menu item if product category is empty
More Articles
If you enjoyed reading this, then please explore our other articles below:
How WordPress Development Services Can Transform Your Website
March 7th, 2025|
Customer engagement models: Optimize your Customer Care strategy
February 21st, 2025|
10 Best Generative AI Platforms and How They Transform Marketing Industry
February 18th, 2025|
WiFi Generations: A Comprehensive Guide to WiFi 5, 6, 7, and 8
January 12th, 2025|
Maximizing Sales with Eye-Catching Banner Images in WooCommerce
December 20th, 2024|
Vector vs. Raster Graphics: Understanding the Difference
December 17th, 2024|
5 Worst WordPress Mistakes to Avoid During Development
December 12th, 2024|
The Future of Mobile App Design: AI and Personalization Trends
December 4th, 2024|
Shopify Polaris: A Blueprint for the Future of eCommerce Design and Development
December 3rd, 2024|
Maximizing Sales with Eye-Catching Banner Images in WooCommerce
December 20th, 2024|eCommerce, WooCommerce|
Boost Your WooCommerce Store with Automated Two-Way Up-Sell Links
May 7th, 2024|eCommerce, WooCommerce|
The Role of UX Principles in Crafting a Winning WooCommerce Store
March 18th, 2024|WordPress, WooCommerce|
Add class to menu item if product category is empty
March 15th, 2024|WordPress, WooCommerce|
Exploring WooCommerce Alternatives for WordPress: A Comprehensive Comparison
February 27th, 2024|WordPress, Plugins, WooCommerce|
Maximizing Sales: The Best Free Abandoned Cart Recovery Plugins and Email Services for Your eCommerce Business
February 26th, 2024|WordPress, eCommerce, Marketing, Plugins, WooCommerce|
Maximizing Sales with Eye-Catching Banner Images in WooCommerce
December 20th, 2024|eCommerce, WooCommerce|
Boost Your WooCommerce Store with Automated Two-Way Up-Sell Links
May 7th, 2024|eCommerce, WooCommerce|
The Role of UX Principles in Crafting a Winning WooCommerce Store
March 18th, 2024|WordPress, WooCommerce|
Add class to menu item if product category is empty
March 15th, 2024|WordPress, WooCommerce|
Exploring WooCommerce Alternatives for WordPress: A Comprehensive Comparison
February 27th, 2024|WordPress, Plugins, WooCommerce|
Maximizing Sales: The Best Free Abandoned Cart Recovery Plugins and Email Services for Your eCommerce Business
February 26th, 2024|WordPress, eCommerce, Marketing, Plugins, WooCommerce|