简体   繁体   English

如何根据在Wordpress上使用的登录名将按钮重定向到其他页面

[英]How to redirect a button to a different page based on used login on Wordpress

I have a button that I have that leads users to a page on WordPress called /portfolio/ , so is there a way that I can redirect users to the /registration/ page until their logged in? 我有一个将用户引导到WordPress上名为/portfolio/的页面的按钮,那么有没有办法可以将用户重定向到/registration/页面,直到他们登录?

I'm using a plugin on WordPress that uses the below code to change the menu per user logged in/logged out. 我正在WordPress上使用一个插件,该插件使用以下代码更改每个登录/注销用户的菜单。

function my_wp_nav_menu_args( $args = '' ) {

if( is_user_logged_in() ) { 
    $args['menu'] = 'logged-in';
} else { 
    $args['menu'] = 'logged-out';
} 
    return $args;
}
add_filter( 'wp_nav_menu_args', 'my_wp_nav_menu_args' );

Is there a way that I can use the if( is_user_logged_in() ) to do the same with a redirect? 有没有一种方法可以使用if( is_user_logged_in() )对重定向执行相同的操作? I can't seem to lock the page down to all users. 我似乎无法将页面锁定给所有用户。

You could so something like this? 你可以这样吗?

if(!is_user_logged_in()) {
    //If user not logged in     
    echo "<script> location.href='http://somesite/registration/'; </script>";
}

This should work if you arent using jquery as its JavaScript. 如果您不使用jquery作为其JavaScript,这应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM