After someone submits a comment this line of codes redirects him to the post (i believe).
Can I modify the code in order to redirect him to a custom URL?

do_action(‘comment_form’, $post->ID)

Ty for the answer,

UPDATE:

my comments.php

<form> 
  .......
  <input name="submit" type="submit" id="submit" tabindex="5" value="Submit" />
  <input type="hidden" name="my_redirect_to" value="http://www.google.com"; />
  <?php comment_id_fields(); ?>
  <?php do_action('comment_form', $post->ID); ?>
  </form>

my functions.php

add_action('comment_post_redirect', 'redirect_to_thank_page'); // Redirect to thank you post after comment
   function redirect_to_thank_page() {
       if ( isset( $_POST['my_redirect_to'] ) ) 
       return $_POST['my_redirect_to']; 
   }

The code does not work, it’s not redirecting to google.com for example.

Any ideas why?
Ty

1
1

Not quite; the redirect occurs inline inside wp-comments-post.php

Use the filter comment_post_redirect to pass back any URL of your choice. Arguments passed are the default redirect & comment object, respectively.

Based on your comments, here’s a suggestion:

function wpse_58613_comment_redirect( $location ) {
    if ( isset( $_POST['my_redirect_to'] ) ) // Don't use "redirect_to", internal WP var
        $location = $_POST['my_redirect_to'];

    return $location;
}

add_filter( 'comment_post_redirect', 'wpse_58613_comment_redirect' );

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *