Awwwards
TopDesignKing

Add Delete & SPAM links to the Front-End comments

One thing is certain when managing a WordPress site with the comments turned on.

– expect comments that bring no value (spam).

Whatever you do, some of them are likely to still get through the filter, and once they do, you have to moderate them. Despite the fact that WordPress’ settings and internal functionality allow for a variety of actions, mess will still happen.

Despite the fact that I do not advise doing so, occasionally you miss something and there it is…

So, what does this do?

This snippet adds two links to the frontend of your site. One for Delete and one for SPAM.

What do these links to?

They will re-direct you to the that specific comment, allowing you to do what you want.

function weszty_web_delete_or_mark_as_spam_comment_link( $id ) {
    if( is_user_logged_in() && current_user_can( 'edit_posts' ) ) {
	echo '<a class="comment-del-spam" href="'.get_bloginfo( 'wpurl' ).'/wp-admin/comment.php?action=cdc&c='.$id.'">DELETE</a>';
	echo '<a class="comment-mark-spam" href="'.get_bloginfo( 'wpurl' ).'/wp-admin/comment.php?action=cdc&dt=spam&c='.$id.'">MARK AS SPAM</a>';
    }
}

You must call this function in the comments.php file and in that file you’ll see this: wp_list_comments( array( whatever ));

The function is called after that last part which means that the links are visible under each comment.

weszty_web_delete_or_mark_as_spam_comment_link( get_comment_ID() );

There is a class given to the links, you can use that in your stylesheet.

Don't be weird.

Would you like more information or do you have a question?

scroll
10%
Drag View Close play