You can use the WordPress function wp_redirect()
. If you want a redirect after login or logout, check the plugin Adminimize, it has an option for this.
Two examples for a redirect in a custom plugin or functions.php
of the theme (the following example uses the variable $pagenow
):
function fb_redirect_1() {
global $pagenow;
if ( 'plugins.php' === $pagenow ) {
if ( function_exists('admin_url') ) {
wp_redirect( admin_url('edit-comments.php') );
} else {
wp_redirect( get_option('siteurl') . '/wp-admin/' . 'edit-comments.php' );
}
}
}
if ( is_admin() )
add_action( 'admin_menu', 'fb_redirect_1' );
An alternative with $_server
, checks the URL too:
function fb_redirect_2() {
if ( preg_match('#wp-admin/?(index.php)?$#', $_SERVER['REQUEST_URI']) ) {
if ( function_exists('admin_url') ) {
wp_redirect( admin_url('edit-comments.php') );
} else {
wp_redirect( get_option('siteurl') . '/wp-admin/' . 'edit-comments.php' );
}
}
}
if ( is_admin() )
add_action( 'admin_menu', 'fb_redirect_2' );