Exciting News! Flipper Code is now WePlugins! Same commitment to excellence, brand new identity.

How to use comment_moderation_subject filter in WordPress

Sandeep Kumar Mishra
Sandeep Kumar Mishra
July 20, 2022
5 minutes read

Using WordPress hooks can be super handy, right? Especially for tweaking things just the way you want them without touching the core files. Let’s dive into the comment_moderation_subject filter, which allows you to change the subject line of comment moderation emails. Here’s how you can get started with this hook.

Parameters

    To use this hook, you need the following parameters:

  • $subject: (string) Subject of the comment moderation email.
  • $comment_id: (int) Comment ID.

Live Example 1: Modifying the Comment Moderation Subject

Here’s how you can change the subject line of the comment moderation email:

    function weplugins_modify_comment_moderation_subject($subject, $comment_id) { 
        // Update the $subject variable according to your website requirements and return this variable. 
        $subject = "New Comment Awaiting Moderation on Your Site!";
        return $subject; 
    }
    // add the filter
    add_filter("comment_moderation_subject", "weplugins_modify_comment_moderation_subject", 10, 2 );
    

Live Example 2: Adding Custom Text to Subject

Sometimes, you might want to add some custom text to the subject line:

    function weplugins_custom_comment_moderation_subject($subject, $comment_id) { 
        $subject .= " - Please Moderate!";
        return $subject; 
    }
    // add the filter
    add_filter("comment_moderation_subject", "weplugins_custom_comment_moderation_subject", 10, 2 );
    

Live Example 3: Removing the Comment Moderation Subject Filter

If you need to remove the filter, you can do it like this:

    function weplugins_remove_comment_moderation_subject_filter() {
        remove_filter("comment_moderation_subject", "weplugins_modify_comment_moderation_subject", 10, 2 );
    }
    add_action('init', 'weplugins_remove_comment_moderation_subject_filter');
    

Remember, you have to provide the same callback function name, priority, and the number of arguments while removing the hook callback.

Access Premium WordPress Plugins

Contact Us

If you need any customization or have questions, feel free to Contact Us. We’re here to help!

Sandeep Kumar Mishra

Sandeep Kumar Mishra

Sandeep Kumar Mishra writes about WordPress and Artificial Intelligence, offering tips and guides to help you master your website and stay updated with the latest tech trends.

Explore the latest in WordPress

Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.