Disable WordPress comment box, on reaching a specific number of comments or if user already posted specific number of comments.
Wordpress , PHP / May 6, 2020

Imagine a use case in which the comment box has to be disabled On reaching a specific number of comments in WordPress post If the user already posted a comment For applying these conditions, the following data are needed Number of comments in a post Number of comments of a User in a WordPress Post   Obtain the number of comments in a WordPress Post To obtain the number of comments in a post, the following built-in function  get_comments_number, can be used.

    Obtain  the number of comments of a User in a WordPress Post To obtain the number of comments in a post, by the logged-in user, the following built-in function  get_comments, can be used.

  Navigate to the themes folder, comment_form  function in comments.php usually outputs the comment form. A condition has to be applied before calling this function.

  On using plugins, this might not work depending on the plugin For more information read the following documentation for built-in functions https://developer.wordpress.org/reference/functions/get_comments_number/   https://developer.wordpress.org/reference/functions/get_comments/ This approach helps in preventing spam comments.

Share this page in social media platforms