Wednesday, 22 April 2015

Wordpress admin panel custom landing page after login

Redirect to different landing page after successful login on wordpress admin panel,

/*To make non-admin users redirect to specified landing page*/

function your_login_redirect()


            // pick where to redirect to, in the example: Posts page
            return admin_url( 'edit.php' );
        } else {
            return admin_url();
add_filter( 'login_redirect', 'your_login_redirect');

Wordpress Disable Admin Panel Menus Based on Role

In wordpress admin panel, if you want to hide certain menu's for non-admins , then add the below code in your current theme's functions.php file.

function remove_menus () {
global $menu;

        $restricted = array(__('Dashboard'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'),  __('Plugins'));
        end ($menu);
        while (prev($menu)){
            $value = explode(' ',$menu[key($menu)][0]);
            if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
      /* To hide menus for non -admin users*/
add_action('admin_menu', 'remove_menus');