X

Redirect admin pages to any location

Stockholm Review - header options

Redirecting the admin pages was something I needed to do for a recent project. The following snippet will let you redirect any of the admin pages to any location you wish based on the user 'capability'. Another option would be to replace wp_redirect with wp_die("some custom message"); to display a message instead of redirecting.



Code Snippet:


function wpsnipp_admin_pages_redirect() {
global $pagenow;
$admin_pages = array(
'edit-tags.php',
'edit-tags.php',
'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', 'wpsnipp_admin_pages_redirect');
}

Comments  Leave a Reply

  1. You can’t use current_user_can() when in the global scope, within a plugin because it will cause Fatal error: Call to undefined function wp_get_current_user().

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!