WordPress让登录用户选择跳转到哪里

// 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);

评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注