Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thegulshankumar/741653d61880293071850af39cc71fe3 to your computer and use it in GitHub Desktop.
Save thegulshankumar/741653d61880293071850af39cc71fe3 to your computer and use it in GitHub Desktop.
Bypass Cache on Comment Post
<?php
/**
* Special condition: If your WordPress has a settings to automatically approve all comments without a manual approval
* In this case, Cloudflare plugin may not purge the cache.
* This is a quick-workaround. After adding this snippet,
* you need to create a rule to bypass the Cache for comment-posted=true query string
*/
add_filter( 'comment_post_redirect', 'redirect_after_comment' );
function redirect_after_comment( $location ) {
$location = add_query_arg( array( 'comment_posted' => 'true' ), $location );
return $location;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment