Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 3 down vote accepted

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:

add_filter( 'comment_post_redirect', 'wpse_58613_comment_redirect' );
function wpse_58613_comment_redirect( $location )
{
    if ( isset( $_POST['my_redirect_to'] ) ) // Don't use "redirect_to", internal WP var
        return $_POST['my_redirect_to'];
}
share|improve this answer
    
Ty very much, I can't use a filter though.... is there a method to modify the form directly inside comments.php? –  webmasters Jul 16 '12 at 1:22
    
Are you saying you want to change where the form is submitted to? Or what happens once a comment is posted? –  TheDeadMedic Jul 16 '12 at 9:22
    
i cannot use filters because I am using a custom code which passes a variable mysitec.om/post/customvar - and maybe I can use something like <input name="redirect_to" type="hidden" value="domain.com/post/customvar"; /> in comments.php –  webmasters Jul 16 '12 at 11:20
1  
Sorry, but you're not making an awful lot of sense - I've taken a guess at what you're after (see the revision). –  TheDeadMedic Jul 16 '12 at 11:45
    
I think it work, ty very much:) Had to replace google.com with my actual url –  webmasters Jul 16 '12 at 16:11

protected by Community Jan 29 '13 at 15:50

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.