Redirecting WordPress Users After Login. Authorization form function.
We give the user a choice where to go after authorization. Haven't figured out how to use it yet, but as an example, this piece of code is the place to be. maybe, you suggest how to use it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<?php // Fields for redirect function custom_login_fields() { ?> <p> <label> <strong>Choose your location: </strong> <select name="login_location"> <option value="">Select …</option> <option value="<?php bloginfo('url'); ?>#banking">Banking</option> <option value="<?php bloginfo('url'); ?>#insurance">Insurance</option> <option value="<?php echo get_permalink(2); ?>">Securities</option> </select> </label> </p><br/> <?php } // Redirect function function location_redirect() { $location = $_POST['login_location']; wp_safe_redirect($location); exit(); } // Add fields to the login form add_action('login_form','custom_login_fields'); // Make sure the redirect happens only if your fields are submitted if ( (isset($_GET['action']) && $_GET['action'] != 'logout') || (isset($_POST['login_location']) && !empty($_POST['login_location'])) ) add_filter('login_redirect', 'location_redirect', 10, 3); ?> |
Among other things, the contact form in WordPress can be easily inserted anywhere in the template.
1 2 3 |
<?php wp_login_form(); ?> |
A function has an integer array of arguments:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php $args = array( 'echo' => true, 'redirect' => 'https://wpsnipp.com', 'form_id' => 'loginform', 'label_username' => __( 'Username' ), 'label_password' => __( 'Password' ), 'label_remember' => __( 'Remember Me' ), 'label_log_in' => __( 'Log In' ), 'id_username' => 'user_login', 'id_password' => 'user_pass', 'id_remember' => 'rememberme', 'id_submit' => 'wp-submit', 'remember' => true, 'value_username' => NULL, 'value_remember' => false ); wp_login_form($args); ?> |
I checked all the code and it works. Udaachi in WordPress Development.
/*
- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.