Question

I am trying to hide wordpress login\register\lostpassword\logout forms and redirect to my own pages I have tried this

add_action('init','possibly_redirect');

function possibly_redirect(){
 global $pagenow;
 if( 'wp-login.php' == $pagenow ) {
  wp_redirect('http://google.com/');
  exit();
 }
}

but this will redirect all pages to 1 page i want to edit individuals like registration and lost password each to redirect elsewhere so I tried this

/* שינוי עמוד התחברות *//**
/*התחברות*/
function possibly_redirect(){
  global $pagenow;
  if( 'wp-login.php' == $pagenow ) {
    if ( isset( $_POST['wp-submit'] ) || //  this is line 33
    else wp_redirect( home_url('/%D7%94%D7%AA%D7%97%D7%91%D7%A8/') ); // or wp_redirect(home_url('/login'));
    exit();
  }
}
add_action('init','possibly_redirect');
/*התנתקות*/
function possibly_redirect(){
  global $pagenow;
  if( 'wp-login.php' == $pagenow ) {
    if ( isset($_GET['action']) && $_GET['action']=='logout') ||   // in case of LOGOUT
    else wp_redirect( home_url() ); // or wp_redirect(home_url('/login'));
    exit();
  }
}
add_action('init','possibly_redirect');
/*איפוס יסמא*/
function possibly_redirect(){
  global $pagenow;
  if( 'wp-login.php' == $pagenow ) {
    if ( isset($_GET['checkemail']) && $_GET['checkemail']=='confirm') ||   // in case of LOST PASSWORD
    else wp_redirect( home_url('/%D7%90%D7%99%D7%A4%D7%95%D7%A1-%D7%A1%D7%99%D7%A1%D7%9E%D7%90/') ); // or wp_redirect(home_url('/login'));
    exit();
  }
}
add_action('init','possibly_redirect');
/*הרשם*/
function possibly_redirect(){
  global $pagenow;
  if( 'wp-login.php' == $pagenow ) {
    if ( isset($_GET['checkemail']) && $_GET['checkemail']=='registered') ) return;    // in case of REGISTER
    else wp_redirect( home_url('/%D7%94%D7%A8%D7%A9%D7%9E%D7%94/') ); // or wp_redirect(home_url('/login'));
    exit();
  }
}
add_action('init','possibly_redirect');

dont get me wrong I have no idea how to write php I took this from some searches and tried to play around so it works... but it does not work... sometimes it shows an error

Parse error: syntax error, unexpected T_ELSE in /home/content/11/9595411/html/luachmodaot/wp-content/themes/boozurk/functions.php on line 33

can someone help me out with this please?

Was it helpful?

Solution

see below for correct php code syntax, but i've no idea if it will work based on what you have given. Are you creating a theme yourself or modifying a theme?

you had a number of errors after the one you posted. Basically your if statement syntax was wrong - should be if(you exist && you == you) {do this please;} else {ok do this instead;} -- if you mess up the brackets you get an error. btw you dont need to check isset $var && $var == something, just check its equal to something, if its not, it will fail.

why do you want to redirect away from the pages? if its something as simple as styling you can do something like this https://premium.wpmudev.org/blog/create-a-custom-wordpress-login-page/. if you dont know php, it might be a place to start rather than creating your own method

function possibly_redirect(){
global $pagenow;
if( 'wp-login.php' == $pagenow ) {
    if ( $_POST['wp-submit'] ) {  //  this is line 33 - the error was telling you had a open statement....syntax for if statement :  if(    ) {      } else {     }   
    wp_redirect( home_url('/%D7%94%D7%AA%D7%97%D7%91%D7%A8/') ); // or wp_redirect(home_url('/login'));
    exit();
}

if( 'wp-login.php' == $pagenow ) {
    if ( $_GET['action']=='logout') { // in case of LOGOUT
    wp_logout();
    wp_redirect( home_url() ); // or wp_redirect(home_url('/login'));
    exit();
    }
}

if( 'wp-login.php' == $pagenow ) {
    if ( $_GET['checkemail']=='confirm') {   // in case of LOST PASSWORD
         wp_redirect( home_url('/%D7%90%D7%99%D7%A4%D7%95%D7%A1-%D7%A1%D7%99%D7%A1%D7%9E%D7%90/') ); // or wp_redirect(home_url('/login'));
    exit();
    }
}

if( 'wp-login.php' == $pagenow ) {
    if ( $_GET['checkemail']=='registered' ) { //return;---> use in function only!!!!!!!!
    wp_redirect( home_url('/%D7%94%D7%A8%D7%A9%D7%9E%D7%94/') ); // or wp_redirect(home_url('/login'));
    exit();
       }
    }
    }

    add_action('init','possibly_redirect');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top