How to Add “delete” and “spam” Buttons to Your Comments

Comment section in a site is really important. It represent interaction between you and your readers. It also keeps posts alive and is an important indicator of a popular post.

Often, We need to edit, delete or mark certain comments as spam. Yes, You can delete or mark them as spam via admin panel, but it would be really nice if We can do it from the blog. By default, WordPress shows the “Edit” link on comments (using the edit_comment_link() function) but not “Delete” or “Spam” links/buttons.

You can read our other tutorial about comment section here :

Ok, here’s the script to add those buttons.

Open your theme’s functions.php file and paste the following code :


function spam_delete_comment_link($id) {
	global $comment, $post;

	if ( $post->post_type == 'page' ) {
		if ( !current_user_can( 'edit_page', $post->ID ) )
			return;
	} else {
		if ( !current_user_can( 'edit_post', $post->ID ) )
			return;
	}

	$id = $comment->comment_ID;
    
	if ( null === $link )
		$link = __('Edit');
		

	$link = '<a class="comment-edit-link" href="' . get_edit_comment_link( $comment->comment_ID ) . '" title="' . __( 'Edit comment' ) . '">' . $link . '</a>';
	$link = $link . ' | <a href="'.admin_url("comment.php?action=cdc&c=$id").'">del</a> ';
	$link = $link . ' | <a href="'.admin_url("comment.php?action=cdc&dt=spam&c=$id").'">spam</a>';
	$link = $before . $link . $after;
	
	return $link;
}

add_filter('edit_comment_link', 'spam_delete_comment_link');

That’s all. Hope This snippet useful for You

credit : wprecipes and smashingmagazine

1 Comment to “How to Add “delete” and “spam” Buttons to Your Comments”

Add Comments (+)

  1. Kat Skinner says:

    Thanks! Just what I needed. This was a quick edit that saved me a lot of time (compared to manually adding the links to wp_list_comments in my theme template.

Trackbacks/Pingbacks

  1. WordPress: The Best of 2011 and Future Predictions | Wptuts+
  2. My Stream » WordPress Year in Review: The Best Tutorials of 2011
  3. Wordpress News - The Best WordPress Tips and Tutorials of 2011Wordpress News
  4. WordPress Year in Review: The Best Tutorials of 2011 | Graphfucker
  5. WordPress Year in Review: The Best Tutorials of 2011 | Simpler Design's
  6. Bangladesh Web Lab | Bangladeshi Web Designer and Developer Blogs – Best WordPress Tips and Tutorials of 2011
  7. WordPress Arena: A Blog for WordPress Developers, Designers and Blogger
  8. 30 useful wordpress tips

Leave a Reply

 

Amazingly Beautiful WordPress Themes