<p>Yep, <code>postLogoutRedirect</code> can be set to a function instead of a static value. So for example, in your template you can generate a hidden field in your logout form (or append a querystring parameter to the logout URL) that contains the path of the current page. Then set this in your general.php:</p>
<pre><code>'postLogoutRedirect' =&gt; function($siteHandle) {
  return Craft::$app-&gt;request-&gt;getParam('myLogoutPathParameterName', '/');
}
</code></pre>
<p>This defaults to the homepage (<code>'/'</code>) if the parameter is not found.</p>

CC BY-SA 4.0
2022-05-18T09:59:08.237Z
Perfect thanks!
iamkeir
CC BY-SA 4.0
2020-11-17T21:16:41.587Z
2020-11-17T21:16:41.587Z
Evan Warner
<p>Is it possible to stay on the same page after logging out from the frontend, assuming that guests can still view that page?</p>
<p>By default, when logging out we are redirected to the homepage or some specific page set with <code>postLogoutRedirect</code> config setting.</p>

<users>
Stay on the same page after logout
# Stay on the same page after logout

(Asked by: username_0 on 2020-11-17)

Is it possible to stay on the same page after logging out from the frontend, assuming that guests can still view that page?

By default, when logging out we are redirected to the homepage or some specific page set with `postLogoutRedirect` config setting.

**Tags:** users


---

## 1 answers

### Answer by username_1 on 2020-11-17. Score: 5 | Accepted answer

Yep, postLogoutRedirect can be set to a function instead of a static value. So for example, in your template you can generate a hidden field in your logout form (or append a querystring parameter to the logout URL) that contains the path of the current page. Then set this in your general.php:
'postLogoutRedirect' => function($siteHandle) {
  return Craft::$app->request->getParam('myLogoutPathParameterName', '/');
}

This defaults to the homepage ('/') if the parameter is not found.

> **Comments:**
> **username_2**: Perfect thanks!  

---

