How To Prevent LoginPress Logout Redirects (Hook)

By default, WordPress redirects the user to the login page after clicking the logout link. This means that after logging out, the user is automatically redirected to the default WordPress login page, where they can enter their login credentials again to gain access to their account.

LoginPress Login Redirects Add-on helps you to redirect their users based on their roles and specific usernames. You can easily control the destination of your visitors and restrict them from accessing specific pages like wp-admin and other sensitive areas of your website (based on their roles, i.e., subscribers).

Note: We assume you’ve already installed and activated LoginPress Pro. If not, see our guide on the topic

But what if you want to prevent the login redirect for a specific user and instead keep them on the default page upon clicking the logout link?

This knowledge base will provide you with an action Hook that will help you change the functionality of LoginPress Login Redirects Add-on and prevent LoginPress from redirecting a specific user/role to a page/post that the site admin defines. 

So, without much ado, let’s get started!

Preventing LoginPress Logout Redirects (Hook)

You can easily change the default behavior of the LoginPress Login Redirects Add-on to prevent LoginPress Redirects. All you need to do is to update the code to your website theme's functions.php file (provided below in this documentation).

Note: It’s recommended to use a child theme to edit the functions.php file instead of the parent theme. There are chances to lose the modified code when you update your theme. It might cause some adverse effects on your website.

To do this, go to the left sidebar of your WordPress admin dashboard, navigate to Appearance, and click the Theme File Editor option.

Theme File Editor

On the next screen, click the Theme Functions on the right-hand side. Scroll down to the bottom of the functions.php file and paste the code.

Note: Here, $condition contains the boolean value and true for no redirection. Make sure to change it accordingly before pasting it into the theme’s functions.php file.

Here is the code for you:

 * Prevent Logout Redirect on a certain user by User_ID.
 * @param $condition The default condition of logout.
 * @returns 
function prevent_loginpress_logout_redirect_callback( $condition ) {
    if ( get_current_user_id() === 1 ) {
        $condition = true;
    return $condition;
add_filter( 'prevent_loginpress_logout_redirect', 'prevent_loginpress_logout_redirect_callback', 10, 1 );

Note: Modify the user ID in the condition (get_current_user_id() === 1) to ensure the user with that ID is prevented from the logout redirection.

Once you’ve added the hook, click the Update File button at the bottom of the screen to save your changes.

Code for Preventing Logout Redirects

That’s it! We hope you understand how to prevent LoginPress Logout Redirects using a hook. 

Let us know how much this knowledge base helped you! 

If you have any doubts or questions related to this matter, please don't hesitate to contact our support team.

Still stuck? How can we help?

Updated on January 3, 2024

LoginPress Support
triangular shape yellowish icon

Frequently Asked Questions (FAQs)

These FAQs answer the most common questions about our WordPress custom login page plugin.

three shapes icon

Where can I get support for LoginPress?

If you need help with LoginPress, you can contact us here. We’ll be happy to answer any questions about the plugin.

Do you have an affiliate program?

Yes, we have an affiliate program that you can sign up for here. As an affiliate, you’ll earn a commission on every sale you refer to us.

Do you offer refunds?

Yes, we offer a 14-day money-back guarantee on all of our plans. If you’re unsatisfied with LoginPress, simply contact us within 14 days of your purchase, and we’ll process a refund.

Can I upgrade my license after my initial purchase?

Yes, you can upgrade your LoginPress license at any time. Simply log into your account and go to the My Downloads page. From here, you can upgrade your license and download the latest version of the plugin.

Will LoginPress slow down my website?

No, LoginPress will not slow down your website. The plugin is lightweight and only loads the necessary files when someone tries to access your login page.

three shapes icon

If you Still have Questions?

Get In Touch