Title: wp_trash_comment
Published: April 25, 2014
Last modified: August 20, 2026

---

# wp_trash_comment( int|WP_Comment $comment_id ): bool

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_trash_comment/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_trash_comment/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_trash_comment/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_trash_comment/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_trash_comment/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_trash_comment/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_trash_comment/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_trash_comment/?output_format=md#wp--skip-link--target)

Moves a comment to the Trash

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_trash_comment/?output_format=md#description)󠁿

If Trash is disabled, comment is permanently deleted.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/wp_trash_comment/?output_format=md#parameters)󠁿

 `$comment_id`int|[WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)
required

Comment ID or [WP_Comment](https://developer.wordpress.org/reference/classes/wp_comment/)
object.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/wp_trash_comment/?output_format=md#return)󠁿

 bool True on success, false on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_trash_comment/?output_format=md#source)󠁿

    ```php
    function wp_trash_comment( $comment_id ) {
    	if ( ! EMPTY_TRASH_DAYS ) {
    		$comment = get_comment( $comment_id );
    		$success = wp_delete_comment( $comment_id, true );

    		if ( ! $success ) {
    			return false;
    		}

    		// Also delete children of top level 'note' type comments.
    		if ( $comment && 'note' === $comment->comment_type && 0 === (int) $comment->comment_parent ) {
    			$children = $comment->get_children(
    				array(
    					'fields' => 'ids',
    					'status' => 'all',
    					'type'   => 'note',
    				)
    			);

    			foreach ( $children as $child_id ) {
    				if ( ! wp_delete_comment( $child_id, true ) ) {
    					$success = false;
    				}
    			}
    		}

    		return $success;
    	}

    	$comment = get_comment( $comment_id );
    	if ( ! $comment ) {
    		return false;
    	}

    	/**
    	 * Fires immediately before a comment is sent to the Trash.
    	 *
    	 * @since 2.9.0
    	 * @since 4.9.0 Added the `$comment` parameter.
    	 *
    	 * @param string     $comment_id The comment ID as a numeric string.
    	 * @param WP_Comment $comment    The comment to be trashed.
    	 */
    	do_action( 'trash_comment', $comment->comment_ID, $comment );

    	if ( wp_set_comment_status( $comment, 'trash' ) ) {
    		delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' );
    		delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' );
    		add_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', $comment->comment_approved );
    		add_comment_meta( $comment->comment_ID, '_wp_trash_meta_time', time() );

    		/**
    		 * Fires immediately after a comment is sent to Trash.
    		 *
    		 * @since 2.9.0
    		 * @since 4.9.0 Added the `$comment` parameter.
    		 *
    		 * @param string     $comment_id The comment ID as a numeric string.
    		 * @param WP_Comment $comment    The trashed comment.
    		 */
    		do_action( 'trashed_comment', $comment->comment_ID, $comment );

    		// For top level 'note' type comments, also trash children.
    		if ( 'note' === $comment->comment_type && 0 === (int) $comment->comment_parent ) {
    			$children = $comment->get_children(
    				array(
    					'fields' => 'ids',
    					'status' => 'all',
    					'type'   => 'note',
    				)
    			);

    			$success = true;
    			foreach ( $children as $child_id ) {
    				if ( ! wp_trash_comment( $child_id ) ) {
    					$success = false;
    				}
    			}
    			return $success;
    		}

    		return true;
    	}

    	return false;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/comment.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/comment.php#L1643)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/comment.php#L1643-L1728)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_trash_comment/?output_format=md#hooks)󠁿

 [do_action( ‘trashed_comment’, string $comment_id, WP_Comment $comment )](https://developer.wordpress.org/reference/hooks/trashed_comment/)

Fires immediately after a comment is sent to Trash.

 [do_action( ‘trash_comment’, string $comment_id, WP_Comment $comment )](https://developer.wordpress.org/reference/hooks/trash_comment/)

Fires immediately before a comment is sent to the Trash.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_trash_comment/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_set_comment_status()](https://developer.wordpress.org/reference/functions/wp_set_comment_status/)`wp-includes/comment.php` |

Sets the status of a comment.

  | 
| [wp_delete_comment()](https://developer.wordpress.org/reference/functions/wp_delete_comment/)`wp-includes/comment.php` |

Trashes or deletes a comment.

  | 
| [wp_trash_comment()](https://developer.wordpress.org/reference/functions/wp_trash_comment/)`wp-includes/comment.php` |

Moves a comment to the Trash

  | 
| [delete_comment_meta()](https://developer.wordpress.org/reference/functions/delete_comment_meta/)`wp-includes/comment.php` |

Removes metadata matching criteria from a comment.

  | 
| [add_comment_meta()](https://developer.wordpress.org/reference/functions/add_comment_meta/)`wp-includes/comment.php` |

Adds meta data field to a comment.

  | 
| [do_action()](https://developer.wordpress.org/reference/functions/do_action/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to an action hook.

  | 
| [get_comment()](https://developer.wordpress.org/reference/functions/get_comment/)`wp-includes/comment.php` |

Retrieves comment data given a comment ID or comment object.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/wp_trash_comment/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_trash_comment/?output_format=md#)

| Used by | Description | 
| [WP_REST_Comments_Controller::handle_status_param()](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/handle_status_param/)`wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php` |

Sets the comment_status of a given comment object when creating or updating a comment.

  | 
| [WP_REST_Comments_Controller::delete_item()](https://developer.wordpress.org/reference/classes/wp_rest_comments_controller/delete_item/)`wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php` |

Deletes a comment.

  | 
| [wp_ajax_delete_comment()](https://developer.wordpress.org/reference/functions/wp_ajax_delete_comment/)`wp-admin/includes/ajax-actions.php` |

Handles deleting a comment via AJAX.

  | 
| [wp_delete_comment()](https://developer.wordpress.org/reference/functions/wp_delete_comment/)`wp-includes/comment.php` |

Trashes or deletes a comment.

  | 
| [wp_trash_comment()](https://developer.wordpress.org/reference/functions/wp_trash_comment/)`wp-includes/comment.php` |

Moves a comment to the Trash

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_trash_comment/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.9.0](https://developer.wordpress.org/reference/since/6.9.0/) | Any child notes are deleted when deleting a note. | 
| [2.9.0](https://developer.wordpress.org/reference/since/2.9.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_trash_comment%2F)
before being able to contribute a note or feedback.