dreieck.com

WordPress logout link (in the navigation or in the content)

If you have registered users in your WordPress installation, you may need an (additional) logout button.

Even with insensitive data in internal areas, many users feel the need to be able to log out.

You can easily create a logout link or button in your navigation (menu) or even in the content area.

You don’t need a plugin for this. Unfortunately, I see again and again that extra plugins are installed for such simple requirements and WordPress is littered with it.

Create logout link

In fact, it is enough if you use a very simple logout link:

https://deine-domain.de/wp-login.php?action=logout

If a registered user visits this link, he will be asked whether he would like to be logged out and can confirm this with a click.

By only using the part after the domain, you can create a logout link without entering the domain. You can use this directly in a WordPress menu, for example, by creating an “individual link”.

Adjust the displayed name and your logout link is ready.

Ideally, your theme or member plugin* offers the option of internal navigation. The link will then only be displayed to logged-in users.

Redirect after logout

By default, the user lands on the login page after logging out. Usually that’s not where you want to land after logging out.

Luckily, you can change this behavior fairly easily, too!

To do this, add the following code to the functions.php of your child theme:

//Weiterleitung zur Startseite nach dem Ausloggen
function redirect_after_logout(){
	wp_redirect( home_url() );
	exit();
}
add_action('wp_logout', 'redirect_after_logout');

After successfully logging out, the user will be redirected to the start page of your WordPress site (with the help of wp_redirect).

Instead of the start page, you can of course also specify any other page – even with a direct URL.

//Weiterleitung zu spezifischer URL nach dem Ausloggen
function redirect_after_logout(){
	wp_redirect( 'https://dreieck.com' );
	exit();
}
add_action('wp_logout', 'redirect_after_logout');

You can also create an extra logout page and provide the user with further information.

This simple trick has helped me many times so that my members can log out safely.

Protect WordPress login: change the error message hint Previous post Protect WordPress login: change the error message hint
WordPress - Restrict access to the login page Next post WordPress – Restrict access to the login page