• I have created a custom login/logout widget on the sidebar. However when a logged in user clicks “logout” it gives the following error: WordPress Failure Notice.You are attempting to log out of websitename
    Do you really want to log out?
    The actual code for the logout link I am using is: <a href="http://www.websitename/wp-login.php?action=logout" alt="logout" title="Logout">Logout</a>

    I have also tried using this code:
    <a href="<?php echo wp_logout_url(); ?>" title="Logout">Logout</a>
    But then I get the following error:
    Error 404 – Page not found!
    The page you trying to reach does not exist, or has been moved. Please use the menus or the search box to find what you are looking for.

    The site of concern is http://www.aintreelane.co.za

    Would anyone be able to assist with this?
    Is this a theme problem or something I am doing wrong?
    Thanks in advance!

Viewing 14 replies - 1 through 14 (of 14 total)
  • I’ve implemented a custom login/logout widget in one of my themes. Perhaps you could download it and grab the code that I used?

    Thread Starter sblob

    (@sblob)

    That would be great! Which theme should I download to find the code?

    Emporium. Have a look at /library/login-widget.php. The script is loaded using:

    // Load login form widget
    function emporium_load_login_widget() {
    	include_once get_template_directory() . '/library/login-widget.php';
    	if( function_exists ( 'wp_login_form' ) ) register_widget( 'Emporium_Login_Widget' );
    }
    add_action( 'widgets_init', 'emporium_load_login_widget' );

    in functions.php

    Thread Starter sblob

    (@sblob)

    Thank you, I appreciate your help!

    My previous query was dumb as you already linked to emporium.

    I have tried using your code and it gives me the same issue: I am getting a 404 error.
    Unfortunately I don’t know enough php to solve why this is happening.

    Moderator bcworkz

    (@bcworkz)

    The WordPress failure might be because you are not providing a nonce parameter to wp-login.php.

    Not sure about the 404 error. Any chance your theme or a plugin is filtering ‘site_url’ or something similar? Also, confirm the url you entered in the admin settings is correct. I once had a similar problem and found the wordpress url somehow got set to something like http:\\http:\\www.sample.com

    Thread Starter sblob

    (@sblob)

    The URL I entered in the admin settings seems fine.
    The code I am currently using is:
    http://www.aintreelane.co.za/wp-login.php?action=logout

    Do you know I link where I can read more about nonce parameters? I’m not sure what parameter parameter to insert?
    Sorry for noob questions!

    Moderator bcworkz

    (@bcworkz)

    Everyone here was a noob once πŸ™‚
    The overview is WordPress Nonces
    FYI, the logout action checks the passed nonce with check_admin_referer('log-out'); which means you should do something like

    $logout_url = 'http://www.aintreelane.co.za/wp-login.php?action=logout';
    $logout_url = wp_nonce_url( $logout_url, 'log-out' );

    which should yield something like http://www.aintreelane.co.za/wp-login.php?action=logout&_wpnonce=cfb7bcd268 .

    Thread Starter sblob

    (@sblob)

    So that code should go into my php somewhere?

    <a href="<?php echo wp_logout_url(esc_url( home_url( '/' )); ?>" title="Logout">Logout</a>

    try this it takes you to homepage

    Thread Starter sblob

    (@sblob)

    Hi Truthseeker, thanks for the help.
    Unfortunately that code gives me a 404 error πŸ™
    Page not found…

    When I use the standard wordpress meta widget the logout link works fine. Is there a way to see what code they use in that widget link?

    sorry a bracket was missing

    <a href="<?php echo wp_logout_url(esc_url( home_url('/'))); ?>" title="Logout">Logout</a>

    takes to home page on logout

    Thread Starter sblob

    (@sblob)

    Still the same issue πŸ™

    Error 404 – Page not found!

    The page you trying to reach does not exist, or has been moved. Please use the menus or the search box to find what you are looking for.

    Is this code you provided the code that the meta widget logout uses? Do you know if there is a way to find this code?

    Really appreciate all the help!

    Moderator bcworkz

    (@bcworkz)

    So that code should go into my php somewhere?

    Right, the output of wp_nonce_url() should be the href for the link the user clicks to logout.

    The Meta widget source is in wp-includes/default-widgets.php, around line 298. You’ll find it simply calls wp_loginout(), which will display the appropriate link depending on the user’s status of in or out. If you check it’s source, you’ll see it uses wp_nonce_url() as well.

    Thread Starter sblob

    (@sblob)

    That is what I thought. I can’t figure out why my custom link won’t work but the logout meta widget works.
    Will check the source out!

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Logout Widget’ is closed to new replies.