【发布时间】:2014-11-26 03:31:26
【问题描述】:
如何将用户从 wp-admin 重定向到另一个自定义页面,例如我想重定向这个 url:
http://example.com/wp-admin
到:
http://example.com/custom
【问题讨论】:
标签: php wordpress .htaccess redirect
如何将用户从 wp-admin 重定向到另一个自定义页面,例如我想重定向这个 url:
http://example.com/wp-admin
到:
http://example.com/custom
【问题讨论】:
标签: php wordpress .htaccess redirect
wp_redirect( $location, $status );
exit;
或者像这样尝试
wp_redirect( home_url( '/custom/' ) );
exit();
【讨论】:
最简单的方法可能是在您的webroot directory 中创建一个.htaccess 文件。
然后把这个写进去:
Redirect /wp-admin http://www.example.com/custom
非常不言自明。 Redirect 从第一个链接 /wp-admin 到第二个链接 http://www.example.com/custom
另一种方法可能是使用 wordpress wp_redirect() 函数,如下所示:
wp_redirect('http://example.com/custom', $status );
【讨论】:
wp-login.php
在您的 functions.php 文件中使用以下代码重定向到另一个 URL。
function redirect_login_page(){
// Store for checking if this page equals wp-login.php
$page_viewed = basename($_SERVER['REQUEST_URI']);
// Where we want them to go
$login_page = http://example.com/custom; //Write your site URL here.
// Two things happen here, we make sure we are on the login page
// and we also make sure that the request isn't coming from a form
// this ensures that our scripts & users can still log in and out.
if( $page_viewed == "wp-login.php" && $_SERVER['REQUEST_METHOD'] == 'GET') {
// And away they go...
wp_redirect($login_page);
exit();
}
}
add_action('init','redirect_login_page');
【讨论】: