Using WordPress ‘comment_flood_message’ PHP filter

The comment_flood_message WordPress PHP filter allows you to modify the comment flood error message displayed when a user submits comments too quickly.

Usage

add_filter('comment_flood_message', 'custom_comment_flood_message');
function custom_comment_flood_message($comment_flood_message) {
    // Your custom code here
    return $comment_flood_message;
}

Parameters

  • $comment_flood_message (string) – The default comment flood error message.

More information

See WordPress Developer Resources: comment_flood_message

Examples

Change the comment flood error message

Modify the default comment flood error message to display a custom message.

add_filter('comment_flood_message', 'change_comment_flood_message');
function change_comment_flood_message($comment_flood_message) {
    $comment_flood_message = 'Please wait a few minutes before posting another comment.';
    return $comment_flood_message;
}

Add an emoji to the comment flood error message

Add an emoji to the beginning of the comment flood error message.

add_filter('comment_flood_message', 'add_emoji_to_comment_flood_message');
function add_emoji_to_comment_flood_message($comment_flood_message) {
    $comment_flood_message = '😅 ' . $comment_flood_message;
    return $comment_flood_message;
}

Display the remaining time before another comment can be posted

Show the remaining time before a user can submit another comment.

add_filter('comment_flood_message', 'display_remaining_time_before_comment');
function display_remaining_time_before_comment($comment_flood_message) {
    $time_left = 60; // Replace with actual remaining time in seconds
    $comment_flood_message = 'Please wait ' . $time_left . ' seconds before posting another comment.';
    return $comment_flood_message;
}