22Aug

WordPress logout link and redirect from front-end

How to add a logout link and redirect to a page after logging out.

How to create a logout link without showing the

With Membershipworks, you can only have one shortcode per page. So, it can be better to create your own logout link rather than using the MW logout shortcode.

Developers used to do an url with <a href=”<?php bloginfo(‘url’); ?>/wp-login.php?action=logout”>Log out</a> but that will show a logout confirmation page saying something like:

You are attempting to log out of [your website name]
Do you really want to log out?

Allow logout without confirmation

Use the PHP wp_logout_url function the in your theme.

<?php echo wp_logout_url(); ?>
or
<?php echo wp_logout_url( home_url() ); ?>

You can also do the redirect with added those lines in your theme functions.php

// LOGOUT redirect
function auto_redirect_after_logout(){
	wp_safe_redirect( home_url() );
	exit();
}
add_action('wp_logout','auto_redirect_after_logout');
Subscribe
Notify of

0 Comments
Oldest
Newest
Inline Feedbacks
View all comments