How to Redirect WordPress Admin Pages to Any Location You Want

x theme

If you are facing a situation to redirect WordPress admin pages to some location. The following code will allow you redirect any admin page you want to any location according to the user “capability or role“.

Paste the code inside functions.php.

function wpulti_admin_pages_redirect() {
global $pagenow;
$admin_pages = array(
'edit-tags.php?taxonomy=category',
'edit-tags.php?taxonomy=post_tag',
'link-manager.php',
'options-writing.php',
'options-reading.php',
'options-discussion.php',
'options-media.php',
'options-privacy.php',
'options-permalink.php',
);
if(in_array($pagenow, $admin_pages)){
wp_redirect( admin_url('/') ); exit;
}
}
if(!current_user_can('edit_post')){
add_action('admin_init', 'wpulti_admin_pages_redirect');
}

Leave a Reply

Your email address will not be published. Required fields are marked *