指定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 &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>
			</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);
?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值