Trouble with logout icon code

Support,

I am having trouble configuring my logout icon at the top of the page. I’ve tried this with no luck: Log Out

I would also like to add a redirect that would redirect users to the login page.

Can you please take a look. Details attached.

Thanks,
Chuck

Hello There,

Thanks for writing in! Upon checking your site, it seems that there is a fatal error with the code you have added in your child theme’s functions,php file (http://prntscr.com/fv83a8). To resolve this, please log in to your ftp and browse to your child theme’s folder. You will need to edit your functions.php file manually. If you cannot figure out which of the line of code causes the issue, please post the contents of the functions.php file in your next reply.

To redirect your login/logout page, please check out this links:


Please let us know how it goes.

Is it possible to have an x-button instead that displays the text “logout” and initiates logging out and redirecting through a url? or is it necessary to change the functions.php?

Thanks,
Chuck

Hello There,

Yes you can add an X button. The only problem is that the position of the x button will be limited to where your post/page content is when you are using Cornerstone. You may a custom code instead and position it in the upper right corner of the page. You can make use of this code in your child theme’s functions.php file:

// Add login log out button on top right corner
// =============================================================================
function add_login_logout_button() { ?>
  <?php if ( is_user_logged_in() ) : ?>
    <div style="position: fixed; top: 50px; right: 30px; z-index: 10000;">
    <?php echo do_shortcode('[button type="real" shape="square" size="mini" href="' . wp_logout_url() . '" title="Example"]Log Out[/button]'); ?>
    </div>
  <?php else : ?>
    <div style="position: fixed; top: 50px; right: 30px; z-index: 10000;">
    <?php echo do_shortcode('[button type="real" shape="square" size="mini" href="' . wp_login_url() . '" title="Example"]Log In[/button]'); ?>
    </div>
  <?php endif; 
}
add_action('wp_footer', 'add_login_logout_button');
// =============================================================================

Hope this helps. Please let us know how it goes.

Support,

I already have a logout link in the top bar that display only when a user is logged in. This is the current code:

<a href="login013579/?action=logout&_wpnonce=e1b4d6e82b" class="wp-logout-url"><i class="x-icon-sign-out" data-x-icon=""></i> Logout </a>

I have also added a rediect fuction in my functions.php file:

// Redirect to Home Page upon logout
// =============================================================================
add_action(‘wp_logout’,‘auto_redirect_after_logout’);
function auto_redirect_after_logout(){
wp_redirect( home_url() );
exit();
}

Problem is this section of my code changes: wpnonce=e1b4d6e82b"
I would like to bypass the Wordpress Failure notice and have the user automatically redirected to the homepage upon clicking the Logout link.

Is this possible?

Thanks,
Chuck

SOLVED

Resolution:

This code is in my customizer topbar:
Logout

I added this to functions.php file:
add_action(‘wp_logout’,‘auto_redirect_after_logout’);
function auto_redirect_after_logout(){
wp_redirect( home_url() );
exit();
}

add_action(‘check_admin_referer’, ‘logout_without_confirm’, 10, 2);
function logout_without_confirm($action, $result)
{
/**
* Allow logout without confirmation
*/
if ($action == “log-out” && !isset($_GET[’_wpnonce’])) {
$redirect_to = isset($_REQUEST[‘redirect_to’]) ? $_REQUEST[‘redirect_to’] : ‘’;
$location = str_replace(’&’, ‘&’, wp_logout_url($redirect_to));;
header(“Location: $location”);
die;
}
}

Hi there,

Thank you for taking time, and share your solution with us. As an alternative solution as this request is not related to our product directly you can use 3rd party plug-ins such as the one below:

Thank you.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.