加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > CMS系统 > wordpress > 正文

给Wordpress指定登录后转向页面代码

发布时间:2020-12-14 14:15:55 所属栏目:wordpress 来源:网络整理
导读:给Wordpress指定登录后转向页面代码,本文来源:wordpress啦 这是一段很有趣的代码,在用户登录的时候,可以选择登录成功之后转向到哪个页面。同样是把这段代码放在functions.php中。 ?php // Fields for redirect function custom_login_fields() { ? p lab

给Wordpress指定登录后转向页面代码,本文来源:wordpress啦

这是一段很有趣的代码,在用户登录的时候,可以选择登录成功之后转向到哪个页面。同样是把这段代码放在functions.php中。

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读