{"id":230581,"date":"2019-12-19T06:45:46","date_gmt":"2019-12-19T06:45:46","guid":{"rendered":"https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/?post_type=docs&#038;p=230581"},"modified":"2026-05-24T21:30:17","modified_gmt":"2026-05-25T04:30:17","slug":"prevent-loginpress-logout-redirects","status":"publish","type":"docs","link":"https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/doc\/prevent-loginpress-logout-redirects\/","title":{"rendered":"How To Prevent or Customize LoginPress Logout Redirects (Hook)"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">By default, WordPress redirects the user to the login page after clicking the logout link. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">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.<\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/add-ons\/login-redirects\/\" target=\"_blank\" rel=\"noreferrer noopener\">LoginPress Login Redirects Add-on<\/a> helps you to redirect your users based on their roles and specific usernames.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can easily control where your visitors go and restrict access to specific pages, such as wp-admin and other sensitive areas of your website, based on their roles (e.g., subscribers).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>Note:<\/em><\/strong><em> We assume you\u2019ve already installed and activated <\/em><a href=\"https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/\" target=\"_blank\" rel=\"noreferrer noopener\"><em>LoginPress Pro<\/em><\/a><em>. If not, see our guide on <a href=\"https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/doc\/how-to-install-and-activate-loginpress-pro\/\" target=\"_blank\" data-type=\"link\" data-id=\"https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/doc\/how-to-install-and-activate-loginpress-pro\/\" rel=\"noreferrer noopener\">How to Install and Activate LoginPress PRO<\/a>.\u00a0<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">But what if you want to prevent the login redirect for a specific user and instead keep them on the default page when they click the logout link?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This knowledge base will provide you with an action <em>hook to modify the functionality of the LoginPress Login<\/em> Redirects Add-on and prevent LoginPress from redirecting a specific user\/role to a page\/post defined by the site admin.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So, without much ado, let\u2019s get started!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Preventing LoginPress Logout Redirects (Hook)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You can easily change the default behavior of the LoginPress Login Redirects Add-on to prevent LoginPress Redirects. All you need to do is update the code in your website theme&#8217;s functions.php file (see the section below in this documentation).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>Note:<\/em><\/strong><em> It\u2019s recommended to use a child theme to edit the functions.php file instead of the parent theme. There is a risk of losing the modified code when you update your theme. It might cause some adverse effects on your website.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To do this, go to the left sidebar of your WordPress admin dashboard, navigate to <strong>Appearance<\/strong>, and click the <strong>Theme File Editor<\/strong> option.<\/p>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6aadf8c2a2944&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6aadf8c2a2944\" class=\"wp-block-image aligncenter size-full wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"313\" height=\"177\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/wp-content\/uploads\/2023\/05\/customizer-4.png\" alt=\"Theme File Editor\" class=\"wp-image-235382\" title=\"\" srcset=\"https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/wp-content\/uploads\/2023\/05\/customizer-4.png 313w, https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/wp-content\/uploads\/2023\/05\/customizer-4-300x170.png 300w\" sizes=\"(max-width: 313px) 100vw, 313px\"><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"https:\/\/2.zoppoz.workers.dev:443\/http\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">On the next screen, click the <strong>Theme Functions <\/strong>on the right-hand side. Scroll down to the bottom of the <strong>functions.php<\/strong> <strong>file<\/strong> and paste the code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>Note:<\/em><\/strong><em> Here, <\/em><strong><em>$condition<\/em><\/strong><em> contains the <\/em><strong><em>boolean value<\/em><\/strong><em> and<\/em><strong><em> is true<\/em><\/strong><em> for <\/em><strong><em>no redirection<\/em><\/strong><em>. Make sure to change it accordingly before pasting it into the theme\u2019s <\/em><strong><em>functions.php file<\/em><\/strong><em>.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here is the code for you:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**\n * Prevent Logout Redirect on a certain user by User_ID.\n *\n * @param $condition The default condition of logout.\n * @returns \n *\/\nfunction prevent_loginpress_logout_redirect_callback( $condition ) {\n    if ( get_current_user_id() === 1 ) {\n        $condition = true;\n    }\n    return $condition;\n}\nadd_filter( 'prevent_loginpress_logout_redirect', 'prevent_loginpress_logout_redirect_callback', 10, 1 );\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><em>Note: <\/em><\/strong><em>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.<\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Once you\u2019ve added the hook, click the <strong>Update File<\/strong> button at the bottom of the screen to save your changes.<\/p>\n\n\n\n<figure data-wp-context=\"{&quot;imageId&quot;:&quot;6aadf8c2a33b1&quot;}\" data-wp-interactive=\"core\/image\" data-wp-key=\"6aadf8c2a33b1\" class=\"wp-block-image aligncenter size-full wp-lightbox-container\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"573\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on--click=\"actions.showLightbox\" data-wp-on--load=\"callbacks.setButtonStyles\" data-wp-on--pointerdown=\"actions.preloadImage\" data-wp-on--pointerenter=\"actions.preloadImageWithDelay\" data-wp-on--pointerleave=\"actions.cancelPreload\" data-wp-on-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/wp-content\/uploads\/2023\/05\/code.png\" alt=\"Code for Preventing Logout Redirects\" class=\"wp-image-235384\" title=\"\" srcset=\"https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/wp-content\/uploads\/2023\/05\/code.png 1000w, https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/wp-content\/uploads\/2023\/05\/code-300x172.png 300w, https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/wp-content\/uploads\/2023\/05\/code-768x440.png 768w\" sizes=\"(max-width: 1000px) 100vw, 1000px\"><button\n\t\t\tclass=\"lightbox-trigger\"\n\t\t\ttype=\"button\"\n\t\t\taria-haspopup=\"dialog\"\n\t\t\tdata-wp-bind--aria-label=\"state.thisImage.triggerButtonAriaLabel\"\n\t\t\tdata-wp-init=\"callbacks.initTriggerButton\"\n\t\t\tdata-wp-on--click=\"actions.showLightbox\"\n\t\t\tdata-wp-style--right=\"state.thisImage.buttonRight\"\n\t\t\tdata-wp-style--top=\"state.thisImage.buttonTop\"\n\t\t>\n\t\t\t<svg xmlns=\"https:\/\/2.zoppoz.workers.dev:443\/http\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewBox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\" \/>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it! We hope you understand how to prevent LoginPress Logout Redirects using a hook.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let us know how much this knowledge base helped you!&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you have any doubts or questions related to this matter, please don&#8217;t hesitate to contact our <a href=\"https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/contact\/\">support team<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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.<\/p>\n","protected":false},"author":15,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","docs_taxonomy":[22],"class_list":["post-230581","docs","type-docs","status-publish","hentry","docs_taxonomy-developers","entry"],"acf":[],"_links":{"self":[{"href":"https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/wp-json\/wp\/v2\/docs\/230581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/wp-json\/wp\/v2\/users\/15"}],"replies":[{"embeddable":true,"href":"https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/wp-json\/wp\/v2\/comments?post=230581"}],"wp:attachment":[{"href":"https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/wp-json\/wp\/v2\/media?parent=230581"}],"wp:term":[{"taxonomy":"docs_taxonomy","embeddable":true,"href":"https:\/\/2.zoppoz.workers.dev:443\/https\/loginpress.pro\/wp-json\/wp\/v2\/docs_taxonomy?post=230581"}],"curies":[{"name":"wp","href":"https:\/\/2.zoppoz.workers.dev:443\/https\/api.w.org\/{rel}","templated":true}]}}