Support » Fixing WordPress » Redirect First Comment

  • Resolved Christopher Roberts


    Hi everyone, my name is Christopher and I am a member of the admin team for Technology Bloggers.

    I am trying to redirect users who post their first comments on the blog to this URL:

    I know this plugin can do it (Comment Redirect by Yoast) and it is what we currently use, however we have to slim down our plugin list, as the memory available to us is just 20MB, and the blog is not running smoothly.

    I am sure it is possible by editing comment-template.php and adding something like

    function comment_redirect( $url, $comment ) {
    		$cc = get_comments( array( 'author_email' => $comment->comment_author_email, 'count' => true ) );
    		if ( 1 == $cc )...

    Any thoughts on how we can do this?


Viewing 1 replies (of 1 total)
  • Christopher Roberts


    Thanks to a post by Boutros AbiChedid I have found a way!

    Add this code to functions.php – I added it right below <?php

    Here is the code – just replace YOUR URL with your first comment redirect page

    * @Author: Boutros AbiChedid
    * @Date:   May 14, 2012
    * @Websites: ;
    * @Description: Redirect to a 'Thank You' page only after the FIRST
    * Post/Page Comment.
    * @Tested on: WordPress version 3.3.2
    function redirect_after_first_comment($url, $comment) {
    	$comment_count = get_comments(
    						'author_email' => $comment->comment_author_email,
    						'count' => true
    	//Check if this is the first Comment (based on the Commenter email)
    	if ( $comment_count == 1 ) {
    		//Redirect URL for first time Commenters.
    		wp_redirect('YOUR URL'); /* MODIFY the Path Accordingly */
    	//Else, return the current post for repeated commenters.
    	return $url = get_comment_link();
    //Hook the 'first_comment_redirect' function to the 'comment_post_redirect' filter action.
    add_filter( 'comment_post_redirect', 'redirect_after_first_comment', 5, 2);

    Hope this helps someone.

Viewing 1 replies (of 1 total)
  • The topic ‘Redirect First Comment’ is closed to new replies.