Search

bbPress Showcase » bbPress Chat

  1. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 908

    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 4 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 4 years ago #
  3. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 908

    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 4 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 4 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 7 months ago #
  6. _ck_
    _ck_

    senior admin
    Joined: Jul '06
    Posts: 908

    offline

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

    Posted 7 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:
32 users online from in the past 30 minutes. 14 bots 18 guests
1,987 views today 8,540 yesterday 16,043 peak. Most at once 43 today 50 yesterday 131 peak. Visited today: Gunnar07, wigbuy123, iplaytheme, guava, skat95, landc01
2,288 posts in 394 topics over 66 months by 430 of 2,168 members. Latest: wigbuy123, JeffreyCasivant, summerfortun