Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

logout redirect only from admin page

For your if condition, use the is_admin function to determine if the user is currently viewing a backend administrative dashboard page or are on the frontend of the site.

So your code above would resemble:

add_action('wp_logout','redirect_after_logout');

function redirect_after_logout(){
  if( is_admin() ) {
    wp_redirect( home_url() );
    exit();
  }
}

For more information, see the codex documentation at https://codex.wordpress.org/Function_Reference/is_admin

Related Posts:

  1. How to change redirect after moving a page to trash?
  2. WordPress redirects to login page when I enter url.com/index.php
  3. Check if wp-login is current page
  4. Check IF is a “single product page” and Check the “role” for a Redirect
  5. How to redirect on particular page in wordpress? [closed]
  6. Can I display the widget admin in the page admin?
  7. Change admin startpage to Pages-page?
  8. Only allow new subpages to be created
  9. Is there a way to remove or hide individual pages on the Edit Pages screen?
  10. Where does the 404 redirection happen?
  11. Associate Page with User
  12. How to disable Page Attributes dropdown in wp-admin
  13. Dashboard–> All Pages “How to create folders?”
  14. How to make certain page templates visible to admin only
  15. Password Protected Page Not Displaying Content After Entering Password
  16. Change the Default Pages Menu View in wp-admin
  17. Redirect “Sorry, you are not allowed to access this page.” to Home
  18. Add a Menu Link (to a WordPress Page) in the Admin Menu/Sidebar
  19. How to redirect a page to subdomain?
  20. Remove pages from backend list *and* update counter accordingly
  21. Slug is redirecting to 404
  22. Edit page’s “Restore the backup” link does nothing
  23. How to redirect login and register pages
  24. If a page does not exist, include a different page?
  25. Missing ‘Page Attributes’ in page edit
  26. How to redirect a page to another?
  27. Admin pages, edit notes of the title of posts and pages
  28. Can’t locate a hidden private page
  29. WordPress Admin Login Redirect Problem
  30. Role – edit page but not publish
  31. Page redirects to archive
  32. Unique page URL redirect to file_get_contents() at domain
  33. Adding Page URL to the Pages Admin Table
  34. Could be a namespace conflict (?) with login form and register form on the same page
  35. Change base URL of pages created by certain users
  36. Redirect page to default subpage
  37. How to use is_admin in page content?
  38. Edit page shown after login in WordPress?
  39. Can’t login to my admin area
  40. Bad pages redirection
  41. Page access only from a specific page in wordpress website
  42. Change page name in admin list
  43. Logout Redirect and also WP-login.php Redirect
  44. WordPress page not taking precedence over server directory
  45. Is it possible to restrict access to specific pages in the admin area based on the page slug?
  46. get_permalink not fetching correct pages
  47. Folder wordpress page redirect
  48. How to rewrite a page url
  49. 404.php only works if I’m logged in. Everybody else redirects to wp-login.php – why?
  50. redirect index.html inside folder to wordpress page of same name
  51. Custom page only editable by one user
  52. Publish page by invoking submit via jQuery
  53. How should I set up a Tumblr blog at a WordPress Page?
  54. accessing the Admin page
  55. remove “Edit” from select pages
  56. URL redirect to home page issue in word press site
  57. Trying to login to my site redirects me to the first page
  58. Cannot use old slug – it just 301s to site home page
  59. Make wordpress pages accessible for Woocommerce logged in users only
  60. Post id(login page) not found
  61. Adding CSS styles to Admin Area PAGES only (not POSTS or CPT)
  62. Group Pages based on Parent in Admin Area
  63. disable trashability for certain pages
  64. Custom admin menu for a selection of pages
  65. Pages redirect me to the homepage
  66. How to access variables from one plugin in another
  67. How can a user login on a wordpress page?
  68. How to change the default location where new post gets stored?
  69. How to make a secondary Pages Screen
  70. Remove element from admin page editing part
  71. Slug of a child page is accessible with and without the parent slug in the URL
  72. Show more than 20 items in pages or posts edit dashboard
  73. How to display last 3 posts (recent posts) in a static page?
  74. How to load javascript on custom page template?
  75. Change page template programmatically ?
  76. Conditional tag to check if ‘page.php’ is being used?
  77. Get top level page parent title
  78. Editing Complex Pages in Visual Mode
  79. Link section within page with slash (/) and not hash (#) without reloading the page
  80. Creating a template using a specific slug name, for a page with a parent page
  81. WordPress admin screen very slow / timing out when editing or adding a new page/custom post
  82. Is there a default template file for child pages / subpages?
  83. Users are redirected to homepage instead of wp-admin
  84. Multiple areas of dynamic content in a page
  85. How to create virtual pages with information from user meta profile fields?
  86. Private pages that work when you are not logged into WP admin
  87. Add custom admin menu item for pages using a certain template
  88. Display latest comments on page with pagination
  89. How to add pages to feed?
  90. Woocommerce Login Redirect not working [closed]
  91. PHP If user is logged in & on home page redirect
  92. Relative instead of absolute links in pages?
  93. Produce a plain page with only a message
  94. Password Protected Page Title
  95. Redirect to Current Page after Login
  96. Login redirect problem
  97. Page displays content from different query?
  98. Making audio playlist by getting page’s parent’s ID
  99. Pages Column Sorting WordPress Version 3.0.3
  100. More Fields Required For Password protect page
Categories pages Tags admin, login, pages, redirect
Why can’t MX records point to an IP address?
Including CSS files in HEAD based on page content

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress