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

Redirect default login page to a custom page [duplicate]

Generally, you need to tell WordPress when to do things. If you just dropped your code in a plugin, then you’re not giving WordPress information on when to execute your commands, and you risk the functions you need not being defined yet.

Right now, your code is saying, “If someone isn’t logged in, always redirect them to the regular login URL,” which is the opposite of what it sounds like you’re trying to do.

Try a function in your plugin file, and attaching it to a hook. Here’s an example:

function wpse_177404_login_screen_redirect()
{
    global $pagenow;

    if ($pagenow == 'wp-login.php' && !is_user_logged_in()) {
        wp_redirect('http://your-site.com/custom-login/');
        exit;
    }
}
add_action('init', 'wpse_177404_login_screen_redirect');

With that, you’re telling WordPress to check if the page is wp-login.php on every load, and if someone isn’t logged in, redirect them to the new page of your choosing.

Be careful when you over-ride these types of Core functionality, as it also impacts password resetting and registration, and can be very easy to frustrate your users by doing these sorts of things.

Related Posts:

  1. How to get Login Error messages on a custom template
  2. Login with email (WP Modal Login)
  3. WordPress login with Phone Number [closed]
  4. Custom Login Page — wp_signon Headers Already Sent?
  5. Possibility to login without password
  6. force logged in user to stay in the dashboard
  7. Checking url from plugin [duplicate]
  8. How to create a custom wordpress plugin for a specific functionality?
  9. How would I go about creating a user ranked post popularity page?
  10. CSV file generation failing
  11. How can I force users to a particular subdomain to log in for MU (Multisite)?
  12. Plugin: Google Analytics for Dashboard error – Timestamp is too far from current time
  13. Updating the Drag-To-Share eXtended share URLs?
  14. “Request has expired” with “Make your site social” (Gigya) plugin
  15. finding whether request is for post, and post id
  16. Building plugin with changeable custom post type values…advice needed
  17. How to get all of the activate_plugin action parameters?
  18. __callStatic method handler passed to add_action causes bug in PHP
  19. Enqueue WordPress plugin scripts below all other JS
  20. Display update notification messages like ‘What’s New’
  21. How to add Internationalization in WordPress using Javascript/React?
  22. CRUD and Frontend show from a custom table without shortcode
  23. How to get specific setting by settings_fields()?
  24. Save / Show multi line text in metabox
  25. Creating mySQL procedure with $wpdb
  26. how to disable blockrenderAppender inside all Innerblocks?
  27. why doesn’t this update part of this plugin work? it take me to nothing here page
  28. Redirection of users away from wp-admin (but not administrators)
  29. WordPress Gutenberg react make import of __experimentalUseInnerBlocksProps which is no more experimetal
  30. Using a custom plugin to capture input data via Ajax and PHP
  31. Python with wordpress plugin
  32. Display post lists in 2nd paragraph
  33. Map Custom Registration Fields to WordPress User Roles
  34. Not able to add option in Sub-Menu under page
  35. How to stop activating a plugin and show admin notice when dependent plugins minimum version is not met
  36. Using a post-signup hook to get user details
  37. How to save generated JWT token to cookies on login?
  38. How to apply a patch via plugin?
  39. Fixing WordPress’s Bug (failed to send buffer of zlib output compression) results in “White Screen of Death”
  40. Disable woocommerce cookies and delete cart data automatically
  41. Ajax contact form widget plugin data not insert in database
  42. link bbpress forum discussion to blogposts
  43. Install Plugin via Code
  44. code is working properly in Core PHP but writing coding in WordPress
  45. Combine scripts from all extensions of the plugin when an extension is activated
  46. Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
  47. Prevent duplicate records in plugin table
  48. Send Custom welcome email to specific user group
  49. woocommerce payment gateway callback not firing [closed]
  50. How to modify WCMP Rest API response?
  51. Fetch Children of Grouped Products Inside WooCommerce Product Loop
  52. White page by using filter template_include
  53. How to fetch products with the price in a page on woocommerce using a form or live search with php
  54. Making a Template for a CPT created by a plugin
  55. Woocommerce dependent plugin
  56. WordPress.org Plugin Directory doesn’t recognise screenshots [closed]
  57. External CSS in WordPress Plugin [closed]
  58. Redirect already logged in users away from a page to a specific page base on user role
  59. How to check current user before all actions and filters?
  60. Owl Carousel2 image not displaying full width when using Stretch row and content, Stretch row and content(no padding) in wordpress
  61. User Session and Stored Cookies not get removed
  62. New databes tables with – WooCommerce – for developers [closed]
  63. How can I prevent my plugin go development trunk [closed]
  64. Plugin-generated pages use Not Found or Pages Archive templates?
  65. How can I make 2 plugins that include different versions of a framework to both use the latest version?
  66. creating html reusable blocks via shortcodes
  67. Add Plugin options as subpage to Theme options page
  68. Is there any kind of theme on WordPress to sell my own movies?
  69. Image upload and download from front-end
  70. Create a navbar filter that filters by a custom field
  71. Change commission_status paid when withdraw_status vendor is completed
  72. Passing an array from shortcode-function to filter-function
  73. custom payment gateway in woocommerce failed to connect to remote api server
  74. wp_remote_get() returns 403 while file_get_contents() does not
  75. Single API call exposed via shortcode with params
  76. Plugin options page with live preview?
  77. Using SVN to upload plugin created with gutenberg blocks
  78. Force quit running background job
  79. Modifying Author Link to add Author Meta in URL
  80. How to output CMB2 select options from repeated groups select elements?
  81. Creating a Callback URL for WordPress Woocommerce to update Order Status
  82. Get Time Taken By Each Action Hook in WordPress
  83. How to export post 2 posts WordPress plugin data [closed]
  84. 306 MB of wp_options occupied by WordPress SEO Plugin, is that normal? [closed]
  85. WordPress plugin creation how to execute .sql in order to insert multiple rows at activation of plugin
  86. Contributive page where people logged in can write
  87. Best way to maintain and update 3rd-party WP plugin when developer is unresponsive?
  88. get 404 when accessing wp-admin/plugin-install.php
  89. What can be reason for no plugin-strings available under stable section on translate.wordpress.org?
  90. Plugin: register_deactivation_hook works perfectly well, while register_activation_hook suddenly stopped working
  91. Are functions in main plugin file called before function bound to register_activation_hook runs?
  92. I want to auto populate data in three fields if one drop down is selected
  93. Best place for if/else piece of code related to custom plugin?
  94. How do you assign a UUID to posts/products/comments/reviews?
  95. Best way to initiate a class in a WP plugin?
  96. correct way to include a library(and its dependent libraries) in wordpress development
  97. How does task scheduler plugin implements cron that is not dependent on page load request? [closed]
  98. Issue Tracker from pre exsisting table [closed]
  99. How to make a implement queue for scheduling tasks in WordPress?
  100. Session destroyed on page redirect
Categories plugins Tags login, plugin-development, plugins, wp-login-form
Remove action working on functions.php but not in a plugin. Why?
save content in to wordpress wp_post table of database

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