WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

A theme normally posts to wp-comments-post.php when someone leaves a comment. When successful, it does a redirect to the page again but tacks on "#comment-" into the URL. What I was wanting to do was leave a message, "Your comment awaits moderation, which takes about 24 hours." Sure, I can intercept location.href and see if it contains "#comment-" in it, and show the moderation message then. But there are other ways one can click on a page and "#comment-" gets shown, which makes this a visual quirk, not the way I intended it.

What's an easy way to make a WordPress theme detect that a comment was just posted and redirected back to the page?

share|improve this question
up vote 2 down vote accepted

The easiest and most straight-forward way is to put appropriate code in your wp_list_comments() callback, that outputs a message if a comment is awaiting moderation.

The usual code looks something like this:

<?php if ($comment->comment_approved == '0') : ?>
<em><?php _e('Your comment is awaiting moderation.') ?>

Otherwise, if you're not using a callback, you can hook into an appropriate action hook, such as pre_comment_content, to inject the same content.

share|improve this answer
I'll test this in a couple days and get back to you. – Volomike Jun 11 '11 at 20:10

protected by Community May 17 '12 at 3:26

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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