Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
wp_重定向在functions.php文件上不起作用_Php_Wordpress - Fatal编程技术网

wp_重定向在functions.php文件上不起作用

wp_重定向在functions.php文件上不起作用,php,wordpress,Php,Wordpress,我有一个场景,如果任何用户是通过在数据库中的wp_users表中添加手动创建的(在导入数据库中用户的csv的情况下),并且如果该用户访问我的站点,那么他将被重定向到欢迎页面。 例如,我的站点域。如果用户访问此站点,他们将被重定向到 为此,我在functions.php文件中使用了以下代码 function redirectUser(){ wp_redirect(home_url('/welcome/')); exit; } add_action('init','redirectUser');

我有一个场景,如果任何用户是通过在数据库中的wp_users表中添加手动创建的(在导入数据库中用户的csv的情况下),并且如果该用户访问我的站点,那么他将被重定向到欢迎页面。 例如,我的站点域。如果用户访问此站点,他们将被重定向到 为此,我在functions.php文件中使用了以下代码

function redirectUser(){
wp_redirect(home_url('/welcome/'));
exit;

}
add_action('init','redirectUser');

但当我刷新我的主页时,页面就会消失。所以我做错了什么。任何帮助都是值得的

运行代码而不添加操作

wp_redirect(home_url('/welcome/'));

// OR

function redirectUser($url){
    wp_redirect(home_url($url));
    exit;
}

redirectUser(home_url('/welcome/'));

看起来像一个无止境的循环。您的站点重定向所有请求,无论是否为欢迎页面。为什么不使用
htaccess
重定向301http://www.example.com/ http://www.example.com/welcome
@Noman。事实上,我想为某些特定用户提供此功能。因此,我无法使用htaccess实现此功能。谢谢@Ahmed。我使用以下代码实现了此功能。我认为通过添加条件,我可以解决我的问题问题.代码在这里.function redirectUserOnFirstVisit(){//ob_start();$actual_link=“http://$\u SERVER[http_HOST]$\u SERVER[REQUEST_URI];$link=explode('/',$actual_link);if(is_user_logged_()){$user_id=get_current_user_id();$last_login=get_选项('lastlogin-'.$user_id);if(empty($last_login-)$user_='id);if(empty($last| last|login){[1243]!='welcome-eq-org'){wp_重定向(home_url('/welcome-eq-org/);退出();}}