Depending on whether user registration is enabled on my site or not, I want to prevent loading of my custom login form and display a popup instead telling the user that registration is disabled.

I have tried to find my way through the Wordpress Codex, but it is rather huge, so I didn't find what I was looking for.

How would the code look like that would do what I want, or what would be the proper Wordpress hook and the proper way to make Wordpress load my popup instead of the login page?

  • How is your custom login form called and used? Is it in a page template or are you calling wp_login_form()?
    – jdm2112
    Commented Jun 7, 2021 at 19:21
  • It is a regular wordpress page and is invoked via a login icon in the site's header. Commented Jun 7, 2021 at 19:28

1 Answer 1


One way to approach this is to intercept the page load with the template_redirect action and test user status before rending the login page. Based on user status you could redirect to another page instead of loading the original page content.

function wpse_is_user_good_enough() {
    if ( ! is_page( 'your-login-page-slug-here' ) ) {
        return;  // Not the login page so return early

    // The login page is loading. Ck user status here and bounce them or send them along
add_action( 'template_redirect', 'wpse_is_user_good_enough' );

The above example will hook the wpse_is_user_good_enough function to the template_redirect action. Test right away if this is the page you wish to intercept; return if not.

If you have a PHP template dedicated to the login page, you can embed your user status test on the page template and skip the rest. Using a page template would allow you to display alternate content instead of redirecting an unauthorized user.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.