如何将用户从wp-admin
重定向到另一个自定义页面,例如,我想重定向此url:
http://example.com/wp-admin
至:
http://example.com/custom
wp_redirect( $location, $status );
exit;
或者试试这个
wp_redirect( home_url( '/custom/' ) );
exit();
最简单的方法可能是在webroot directory
中创建一个.htaccess
文件。
然后把这个写进去:
Redirect /wp-admin http://www.example.com/custom
非常不言自明。从第一链路/wp-admin
到第二链路http://www.example.com/custom
的Redirect
另一种方法可能是使用wordpress wp_redirect()
函数,类似于以下内容:
wp_redirect('http://example.com/custom', $status );
在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');