Redirect First Time Commenters to a Custom WordPress Page

For reasons best known to you, redirecting readers or site visitors commenting on your blog for the first time to say, a Thank You for Commenting page would be fascinating.

The code snippet below does the job perfectly well.


function redirect_first_time_commenters( $url, $comment ) {

	// get count of user comment
	$comment_count = get_comments( array( 'author_email' => $comment->comment_author_email, 'count' => true ) );

	// if this is the user first comment, redirect to the "Thank You" Page
	if ( 1 == $comment_count ) {
		$url = 'http://yoursite.com/thank-you-page/';
	}

	return $url;
}

add_filter( 'comment_post_redirect', 'redirect_first_time_commenters', 10, 2 );

Change http://yoursite.com/thank-you-page/ to the page URL you wish to redirect a first time commenter to.

Don’t miss out!
Subscribe to My Newsletter
Invalid email address