WordPress.org

Ready to get started?Download WordPress

Forums

Comment redirect back to originating page? (10 posts)

  1. Scott Chandler
    Member
    Posted 3 years ago #

    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

  2. Scott Chandler
    Member
    Posted 3 years ago #

    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.

  3. inspirationally
    Member
    Posted 3 years ago #

    try

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

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

  4. Scott Chandler
    Member
    Posted 3 years ago #

    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

  5. Scott Chandler
    Member
    Posted 3 years ago #

    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); ?>
  6. josepilove
    Member
    Posted 3 years ago #

    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().'"/>',
    
        );
  7. Scott Chandler
    Member
    Posted 3 years ago #

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

  8. josepilove
    Member
    Posted 3 years ago #

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

  9. Scott Chandler
    Member
    Posted 3 years ago #

    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.

  10. josepilove
    Member
    Posted 3 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags