Support » Fixing WordPress » Log out link with redirect to front page

  • Resolved fUzZy89

    (@fuzzy89)



    Hi! Before I used this code to redirect to the front page when logging out:

    Before this code worked:
    
    <a href="<?php bloginfo('url') ?>/wp-login.php?action=logout&amp;redirect_to=<?php echo urlencode($_SERVER['REQUEST_URI']) ?>">Logg ut</a>
    
    I tried this now, but it does not work anymore, why?

    After the latest updates this code does not work anymore. Why?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thank you! It worked!

    This is how I did it:
    <li><a href="<?php echo wp_logout_url('$index.php'); ?>">Logg ut</a></li>

    I’m experiencing a similar (if not exactly the same) problem as this in WordPress 2.7.1 whereby I’m using wp_logout_url to generate an appropriate URL. If the user happens to be viewing a page other than the front/home page of the site when they logout then they are redirected back to the correct page – however, if the user attempts to logout on the front page (even though wp_logout_url seems to have generated a valid nonced redirect URL to the front page of the website, it ends up displaying the a single page containing the most recent published post.

    Here is the code I’m using to generate the logout URL:

    <?php is_home() ? $logout_url = get_bloginfo('home') : $logout_url = get_permalink(); echo wp_logout_url($logout_url); ?>

    Any ideas – this one has had me scratching my head for a few days now – annoying, but not the end of the world 🙂

    Hi,

    Refer these:

    [spam link moderated]

    http://codex.wordpress.org/Template_Tags/wp_logout_url

    Thanks,

    Shane G.

    Hi Shane,

    Thanks, but I’ve already read (and re-read) the Codex entry for wp_login_url several times now, and I’ve tried the $index.php solution already listed in fUzZy89’s earlier post – neither of which work for me. As I said in my original post, wp_logout_url() does appear to be generating a correctly formed logout URL which points back to the homepage URL of my website, i.e.

    http://www.mysite.com/blog/wp-login.php?action=logout&redirect_to=http://www.mysite.com/blog/&_wpnonce=1234567890

    …but, when this URL is used, WordPress ends up going to the most recent post instead, i.e.

    http://www.mysite.com/blog/2009/05/20/my-most-recent-post

    I’ve also tested by disabling all plugins just in case any of those were hooking into the login/logout or post viewing routines, but sadly this didn’t solve the problem either.

    Just to recap, the redirect works fine on ALL other pages EXCEPT the front page. If a user attempts to log out whilst viewing the front page, then they are logged out successfully, but redirected to my most recent post even though the logout URL is supposedly redirecting them back to the front page of the site.

    I suspect it might be something to do with a combination of my Settings -> Reading -> Front Page Displays option being set to Your Latest Posts and the fact that the template I’m using contains a file called home.php

    ballinascreen, did you ever get this figured out? I’m almost sure you’re on the right track as I’m having the same issue… logout redirects to the latest post. My theme (Mimbo 3) uses a custom front page and Front Page Displays is also set to Latest Posts.

    Sadly no – I’ve not managed to get to the bottom of it yet – its a low priority issue for me at the minute – I had hoped there was an obvious solution or reason for why WordPress is behaving this way. Like you, the theme template I’m using (TheStars) uses a custom front page. It’s just frustrating that wp_logout_url() does appear to be generating a valid redirect URL, but then WordPress (in its infinite wisdom, decides to map this internally to the latest post). I did start tracing my way through the code at one point, but gave up when it started getting a little too involved for me – its a little side-effect that I (and my users) can put up with for now….

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Log out link with redirect to front page’ is closed to new replies.