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

I work on a site that is entirely cached by a CDN. We are about to roll out comments and will be moderating every comment before it goes live. When someone posts a comment and the page is rendered with a message indicating their comment is being held in moderation. What I don't want is for the CDN to cache this page with the moderation message. What can I do to prevent this?

Ideally I would be able to hook in somewhere and return the URL with a query string in it which aren't cached by our CDN.

share|improve this question

Figured it out. Looking at wp-comments-post.php there is a filter called comment_post_redirect which I used to check if the comment was approved and then added a query string to the URL. So easy.

//A query string needs to be added when redirecting back to the post after a comment is posted and not approved. This ensures the page with the "Your comment is awaiting moderation." message won't be cached by the CDN and seen by the rest of the world.  
function add_query_string_to_comment_redirect($location, $comment) {
    if( !$comment->comment_approved ) {
        $location = add_query_arg( array( 'moderated' => '' ), $location);
    return $location;
add_filter('comment_post_redirect', 'add_query_string_to_comment_redirect', 10, 2);
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.