Wordpress - Admin Page Redirect
/**
* Redirect admin pages.
*
* Redirect specific admin page to another specific admin page.
*
* @return void
* @author Michael Ecklund
*
*/
function disallowed_admin_pages() {
global $pagenow;
# Check current admin page.
if ( $pagenow == 'edit.php' && isset( $_GET['post_type'] ) && $_GET['post_type'] == 'page' ) {
wp_redirect( admin_url( '/post-new.php?post_type=page' ) );
exit;
}
}
Fire the above function on the hook admin_init
.
add_action( 'admin_init', 'disallowed_admin_pages' );
Alternate syntax:
/**
* Redirect admin pages.
*
* Redirect specific admin page to another specific admin page.
*
* @return void
* @author Michael Ecklund
*
*/
add_action( 'admin_init', function () {
global $pagenow;
# Check current admin page.
if ( $pagenow == 'edit.php' && isset( $_GET['post_type'] ) && $_GET['post_type'] == 'page' ) {
wp_redirect( admin_url( '/post-new.php?post_type=page' ) );
exit;
}
} );
Michael's solution appears to be intended for use inside a class, so for anyone wanting a standalone function which will work directly in functions.php, the example below includes a redirect from customize.php to a theme options page and the one from Michael's original function.
function admin_redirects() {
global $pagenow;
/* Redirect Customizer to Theme options */
if($pagenow == 'customize.php'){
wp_redirect(admin_url('/admin.php?page=theme_options', 'http'), 301);
exit;
}
/* OP's redirect from /wp-admin/edit.php?post_type=page */
if($pagenow == 'edit.php' && isset($_GET['post_type']) && $_GET['post_type'] == 'page'){
wp_redirect(admin_url('/post-new.php?post_type=page', 'http'), 301);
exit;
}
}
add_action('admin_init', 'admin_redirects');