This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
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
- $subject: (string) Subject of the comment moderation email.
- $comment_id: (int) Comment ID.
To use this hook, you need the following parameters:
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.
Contact Us
If you need any customization or have questions, feel free to Contact Us. We’re here to help!
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.