WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Anyone know how to add quick comment moderation links for users who have permission to add/edit posts and comments? (Upprove / Unappove / Edit / Spam / Trash ). Note: in my comments.php I call the loop with <?php wp_list_comments(); ?>

share|improve this question
up vote 6 down vote accepted

Per default wp_list_comments() calls the class Walker_Comment. Its method start_el() calls edit_comment_link() and here we find a filter for your question: It is called 'edit_comment_link' and it passes two variables, the link text and the comment ID, which we can use.

The URLs to mark a comment as spam or to delete it are:

  • wp-admin/comment.php?c=1&action=cdc&dt=spam for spam, and
  • wp-admin/comment.php?c=1&action=cdc for deletion.

We can add a parameter redirect_to= to send us back to the post after the comment was trashed.

Here is a sample plugin I just hacked together (GitHub address):

<?php # -*- coding: utf-8 -*-
 * Plugin Name: T5 Comment moderation links
 * Version:     2012.06.04
 * Author:      Thomas Scholz <info@toscho.de>
 * Author URI:  http://toscho.de
 * License:     MIT
 * License URI: http://www.opensource.org/licenses/mit-license.php

if ( ! function_exists( 't5_comment_mod_links' ) )
    add_filter( 'edit_comment_link', 't5_comment_mod_links', 10, 2 );

     * Adds Spam and Delete links to the Sdit link.
     * @wp-hook edit_comment_link
     * @param   string  $link Edit link markup
     * @param   int $id Comment ID
     * @return  string
    function t5_comment_mod_links( $link, $id )
        $template = ' <a class="comment-edit-link" href="%1$s%2$s">%3$s</a>';
        $admin_url = admin_url( "comment.php?c=$id&action=" );

        // Mark as Spam.
        $link .= sprintf( $template, $admin_url, 'cdc&dt=spam', __( 'Spam' ) );
        // Delete.
        $link .= sprintf( $template, $admin_url, 'cdc', __( 'Delete' ) );

        // Approve or unapprove.
        $comment = get_comment( $id );

        if ( '0' === $comment->comment_approved )
            $link .= sprintf( $template, $admin_url, 'approvecomment', __( 'Approve' ) );
            $link .= sprintf( $template, $admin_url, 'unapprovecomment', __( 'Unapprove' ) );

        return $link;

Screenshot with TwentyEleven (order reversed by the stylesheet):

enter image description here

share|improve this answer
Works fine! Many thanks toscho! – Arg Geo Jun 4 '12 at 20:12
Great piece of code. Is there a way to add the approve link as well? – davebowker Mar 5 '13 at 16:08
@davebowker See my update. – toscho Mar 5 '13 at 16:10
Magic. Cheers, toscho! – davebowker Mar 5 '13 at 16:57
@toscho the Approve and Unapproved link actually dont work. It redirect to "Are you really want to do this" page. Will you please fix the issue and update the code? – mha Apr 23 '13 at 13:56

This is what I use (added as a reference — toscho's answer IS BETTER for many reasons):

<?php if (current_user_can('edit_post')) {
    $id = get_comment_ID();
    echo ' <a href="'.admin_url("comment.php?action=cdc&c=$id").'">[Delete]</a>';
    echo ' <a href="'.admin_url("comment.php?action=cdc&dt=spam&c=$id").'">[Spam]</a>';
} ?>

Most themes already come with an "Edit" link, so I didn't include that.

Example Preview:

Delete Spam

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.