WordPress.org

Support

Support » How-To and Troubleshooting » Comment redirect back to originating page?

Comment redirect back to originating page?

  • Hello

    I have the ability for users to view and post comments on any page (main, archive, tags, and search results), but after a comment is posted the user is redirected to the single post page. Is there any way to redirect them back to the page they commented on?

    Here’s the blog: scottchandler.ca/research

Viewing 9 replies - 1 through 9 (of 9 total)
  • Bump? I’ve gone through the support forums and all the suggestions for this seem to use the old pre-Wordpress 3 comments implementation and they don’t work anymore . I’ve found the redirect_to tag that I can add to a hidden field, but I don’t know how to get the url of whatever page the user is currently viewing.

    try

    name=”redirect_to” value=”<?php the_permalink() ?>”

    but I’m a newbie on this kind of things.

    Thanks, but this takes the user to a blank page with the URL http://scottchandler.ca/research/wp-comments-post.php?phpthe_permalink?#comment-21

    I’ve seen various solutions that use php, but when I implement them it will redirect to something like “http://scottchandler.ca/research/wp-comments-post.php?phpget_permalink;?#comment-29”

    Is there something about how I’m writing the code? Here’s what I have for the comment form:

    <?php $fields =  array(
            'author' => '<p class="comment-form-author">' . ( $req ? '<span class="required">*</span>' : '' ) . '<input class="text" id="author" name="author" type="text" value="First name"' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
            'redirect_to' => '<input type="hidden" name="redirect_to" value="<?php get_permalink(); ?>"/>',
    
        );
        $new_defaults=array('title_reply'=>'',
    'fields'=>$fields,
    'comment_notes_after'  => '',
    
    'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( '', 'noun' ) . '</label><input id="comment" name="comment" value="A quick note."  aria-required="true"></input</p>',
    
    'label_submit'         => __( 'Submit' ),
    'comment_notes_before' => '',
    );  comment_form($new_defaults); ?>

    at a glance i would say that the problem is that you are including the PHP tags again in the $fields array. try this.

    <?php $fields =  array(
            'author' => '<p class="comment-form-author">' . ( $req ? '<span class="required">*</span>' : '' ) . '<input class="text" id="author" name="author" type="text" value="First name"' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
            'redirect_to' => '<input type="hidden" name="redirect_to" value="'.get_permalink().'"/>',
    
        );

    Thanks! The PHP works now, but not that tag as a way of redirecting. Will keep looking.

    really? i took this and just manually added <input type='hidden' name='redirect_to' value='<?php bloginfo('home')?>/blog'/> as HTML and it worked…

    But wouldn’t <?php bloginfo(‘home’)?> just bring you back to the main page of the blog? I’m looking for something that will redirect the commenter back to whatever page they were visiting, such as archive, search, tag etc.

    oh right. yea, i think you need to get the ID of the page you are on and pass that into the get_permalink() function.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Comment redirect back to originating page?’ is closed to new replies.
Skip to toolbar