Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-05-18T09:59:08.237Z
Answers.Text: Perfect thanks!
Answers.UserDisplayName: iamkeir
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-11-17T21:16:41.587Z
Answers.LastActivityDate: 2020-11-17T21:16:41.587Z
Answers.UserDisplayName: Evan Warner
Body: <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>
  
Tags: <users>
Title: Stay on the same page after logout
ThreadText: # 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!  
  
  ---
  
  