如果用户未登录,则重定向用户

时间:2012-09-24 作者:Joshua

如果用户输入url www.abc。如果他没有登录,那么我们想将他重定向到www.abc。com/de。如何在WordPress中执行此操作?

1 个回复
SO网友:Ryan Koehler

function redirect_user() {    
   if ( $_SERVER[\'HTTP_HOST\'].$_SERVER[\'REQUEST_URI\'] == \'www.abc.com/\' ) {
        if ( ! is_user_logged_in() ) {
           wp_redirect( \'http://www.abc.com/de/\' );
           exit;
        }
    }
}
add_action( \'init\', \'redirect_user\' );
你是说这样的事吗?

结束

相关推荐

需要将wp_reDirect放在哪里才能使其工作?

我在mysite/post\\u id/edit上有一个前端帖子编辑页面,正在尝试将非作者的用户重定向回帖子。以下是我正在使用的代码: <?php global $current_user; get_currentuserinfo(); if($post->post_author != $current_user->ID): wp_redirect( the_permalink() ); exit; ?>