Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

1 Answer

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
add comment

protected by Community May 17 '12 at 3:26

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

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.