User controlled optional login redirect

Adding this snippet to the functions.php of your wordpress theme will let user controlled optional login redirect with a select menu.




// Fields for redirect
function custom_login_fields() {
<strong>Choose your location: </strong>
<select name="login_location">
<option value="">Select &hellip;</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>
// Redirect function
function location_redirect() {
$location = $_POST['login_location'];
// Add fields to the login form
// 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);

Leave a comment