Search

bbPress Showcase » bbPress Chat

  1. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 884

    offline

    If you'd like to give the user a friendly redirect back to the topic (or forum) they were at just before they logged in (instead of the front page) simply open the login-form.php template in your theme and add this BEFORE the final </form>

    <input type="hidden" name="re" value="<?php echo "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"].'?'.$_SERVER["QUERY_STRING"]; ?>" />
    <input type="hidden" name="_wp_http_referer" value="<?php echo  bb_get_option( 'uri' ) ?>" />
    Posted 3 years ago #
  2. d0pp13r
    d0pp13r

    junior member
    Joined: Apr '08
    Posts: 5

    offline

    can this be used for WP as well? seems to be a very general code, so is it just bb_get_option --> wp_get_option modification?

    Posted 3 years ago #
  3. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 884

    offline

    WordPress has had this ability built in since 2.0 (or possibly earlier).

    Just add ?redirect_to=(url here) to any of the login/logout urls.

    ie. on your sidebar through PHP you can do it as:

    <a href="<?php echo get_settings('siteurl'); ?>/wp-login.php?redirect_to=<?php echo $_SERVER["REQUEST_URI"]; ?>"> <?php _e('Login'); ?> </a>
    <a href="<?php echo get_settings('siteurl'); ?>/wp-register.php?redirect_to=<?php echo $_SERVER["REQUEST_URI"]; ?>"><?php _e('Register'); ?> </a>
    Posted 3 years ago #
  4. d0pp13r
    d0pp13r

    junior member
    Joined: Apr '08
    Posts: 5

    offline

    neato - very useful - thanx!

    were rebuilding our login function ATM, but ill keep this tip and add $_SERVER["REQUEST_URI"]; like you suggest.

    for handshake.se its not only the login fields in the sidebar, its also in the comments loop if youre not logged in...

    Posted 3 years ago #
  5. light
    User has not uploaded an avatar

    member
    Joined: Nov '09
    Posts: 36

    offline

    Nice tip..

    But how we can redirect users to a custom url after logout?
    Like I want to redirect them to google.com when they hit logout.
    Thanks

    Posted 3 months ago #
  6. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 884

    offline

    @light just change the <?php echo bb_get_option( 'uri' ) ?> to the url you want.

    Posted 3 months ago #

RSS feed for this topic

Post a reply to “trick to redirect user back to original page after login”

You must log in to post.

keep _ck_ coding >> donate $5 <<     Theme Switcher:
34 users online from in the past 30 minutes. 11 bots 22 guests 1 members: mccawphoto
118 views today 7,784 yesterday 14,010 peak. Most at once 39 today 63 yesterday 131 peak. Visited today: mccawphoto
2,240 posts in 380 topics over 63 months by 425 of 1,992 members. Latest: shairah27, Augustine01, MichaelGomez