WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Logout to redirect to home page. (3 posts)

  1. jarvisx
    Member
    Posted 2 years ago #

    I'm trying to add a text logout button to a page that will either redirect to the homepage or the page same page instead of going to the wordpress login page.

    Spent about an hour reading through articles to no resolve.

    I've tried this: http://codex.wordpress.org/Function_Reference/wp_logout_url and it simply won't display anything on the page.
    The only way I've managed to get the logout working is by
    <a href="http://www.url.com/wp-login.php?action=logout">Logout</a> and that redirects to the wordpress login page which I don't want.

  2. Sergey
    Member
    Posted 2 years ago #

    in WP_LOGIN I just specified the URL. Hope this will work for you.

    $redirect_to = !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : 'wp-login.php?loggedout=true';
    wp_safe_redirect( $redirect_to );
    exit();

    $redirect_to = 'http://www.mafclubs.com';
    wp_safe_redirect( $redirect_to );
    exit();

    break;

  3. jarvisx
    Member
    Posted 2 years ago #

    Worked brilliantly. Thank you!

    The only thing is the

    $redirect_to = 'http://www.mafclubs.com';
    wp_safe_redirect( $redirect_to );
    exit();

    Needs to sit above:

    $redirect_to = !empty( $_REQUEST['redirect_to'] ) ? $_REQUEST['redirect_to'] : 'wp-login.php?loggedout=true';
    wp_safe_redirect( $redirect_to );
    exit();

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags