WordPress Comments
Comments let your visitors talk about your posts. They are good for a community, but they also bring spam, so you have to set them up with care.
Discussion settings
Open Settings > Discussion. These are the important options and their default values:
$ wp option get default_comment_status
open
$ wp option get comment_moderation
0
$ wp option get comment_previously_approved
1
$ wp option get require_name_email
1
$ wp option get close_comments_for_old_posts
0
$ wp option get close_comments_days_old
14
$ wp option get thread_comments
1
| Option | Meaning |
|---|---|
| default_comment_status | New posts accept comments (open) or not (closed) |
| comment_moderation | If 1, every comment waits for your approval |
| comment_previously_approved | Auto approve the comments of people who had an approved comment before |
| require_name_email | Commenters must give name and email |
| close_comments_for_old_posts | Close the comments after some days |
| thread_comments | Allow replies to comments (nested) |
Comment status
| Status | Meaning |
|---|---|
| hold (Pending) | Waiting for approval, not visible |
| approve (Approved) | Visible on the post |
| spam | Marked as spam |
| trash | Deleted, can be restored |
Manage comments with WP-CLI
$ wp comment create –comment_post_ID=1 –comment_author="Riya" –comment_author_email="riya@example.com" –comment_content="Nice post, thanks!" –comment_approved=0 –comment_date="2026-02-05 12:00:00" –porcelain
2
$ wp comment list –fields=comment_ID,comment_author,comment_approved
comment_ID comment_author comment_approved
2 Riya 0
1 A WordPress Commenter 1
$ wp comment approve 2
Success: Approved comment 2.
$ wp comment spam 1
Success: Marked comment 1 as spam.
$ wp comment list –fields=comment_ID,comment_author,comment_approved
comment_ID comment_author comment_approved
2 Riya 1
$ wp comment count
approved: 1
spam: 1
trash: 0
post-trashed: 0
all: 1
moderated: 0
total_comments: 2
How to fight spam
- Keep comment moderation on, or at least allow only previously approved commenters.
- Use an anti spam plugin like Akismet (it comes with WordPress, but you must activate it).
- Close the comments on old posts, and turn them off on pages where you do not need them.
- If you do not want any comments, set default_comment_status to closed, or use a plugin to disable them.
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |