0

I created a maintenace template, and redirected to the folder where it is located via the functions.php file inside the theme folder;

this is the code:

function maintenance_redirect(){
if( !is_user_logged_in()){
  include("maintenance/index.html");
            exit();
}
    }
add_action( 'init' ,'maintenance_redirect' );

but i can't access to the log in page via wp-login.php or wp-admin/ beacause i get redirected to the maintenance page, how can i esclude from redirection the path of log in page?

Thanks in advance :)

  • possible duplicate of Check if we're on the wp-login page? – Stephen Harris Aug 29 '14 at 15:33
  • See also related trac discussion: core.trac.wordpress.org/ticket/19898 – Stephen Harris Aug 29 '14 at 15:36
  • Is there any particular reason you didn't use the built in maintenance mode and template, or one of the maintenance mode plugins? – Tom J Nowell Aug 29 '14 at 15:40
  • @TomJNowell more than a maintenance template, the template is for a preview, before the site is open to the public, so I prefer to use a custom one – user50899 Aug 29 '14 at 15:44
  • @StephenHarris Thank you very much for the solutions, I see right away if they do in my case – user50899 Aug 29 '14 at 15:46
0

Use the hook template_redirect instead - this will ensure it only runs on the front-end of your site, and not for the admin, login, registration or signup pages.

function wpse_159552_maintenance() {
    if ( ! is_front_page() ) {
        wp_redirect( home_url() );
        exit;
    }

    include 'maintenance/index.html';
    exit;
}

add_action( 'template_redirect', 'wpse_159552_maintenance' );
  • it works :D, but it shows the full url redirection, there's a way to stay only in domain.com? – user50899 Aug 29 '14 at 16:36
  • Of course (see revision). But I don't think it's necessary for a maintenance page. – TheDeadMedic Aug 29 '14 at 16:43
  • tried, but if i try to login via wp-login.php i get redirected again – user50899 Aug 29 '14 at 16:55
  • Do you add the code I provided to the template_redirect hook? – TheDeadMedic Sep 1 '14 at 10:20
  • sure, but it redirects me again to the homepage, maybe could try the hook template_include – user50899 Sep 2 '14 at 9:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy