Recently I worked on a WordPress site where I wanted to be able to customise the dashboard for different user roles. WordPress has the default roles of administrators, editors, authors, contributors and subscribers. It’s not too much to assume you might not want to show your editors or authors all the details of your blog posts etc and placing these short code snippets into your theme’s functions.php file will allow you to do just that.
Clearing up
Lets get rid of the incoming links widget for authors and editors and then clean up some of the other boxes for everyone:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | function tidy_dashboard() { global $wp_meta_boxes, $current_user; // remove incoming links info for authors or editors if(in_array('author', $current_user->roles) || in_array('editor', $current_user->roles)) { unset($wp_meta_boxes['dashboard']['normal ']['core']['dashboard_incoming_links']); } // remove the plugins info and news feeds for everyone unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); } //add our function to the dashboard setup hook add_action('wp_dashboard_setup', 'tidy_dashboard'); |
Here’s a full list of how to unset each of the current default dashboard widgets:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | //Right Now - Comments, Posts, Pages at a glance unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']); //Recent Comments unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']); //Incoming Links unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']); //Plugins - Popular, New and Recently updated Wordpress Plugins unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']); //Wordpress Development Blog Feed unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']); //Other Wordpress News Feed unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']); //Quick Press Form unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']); //Recent Drafts List unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']); |
Add your own – Private pages menu
Perhaps rather than the default information, you have other items you’d like to be on the dashboard for authors or editors etc? I often add a dashboard widget to list private pages. Here’s how:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | // function to display widget function display_dashboard_widget() { //define arguments for WP_Query() $qargs = array( 'post_type'=>'page', 'post_status'=>'private' ); // perform the query $q = new WP_Query(); $q->query($qargs); // setup the content with a list $widget_content = '<ul>'; // execute the WP loop while ($q->have_posts()) : $q->the_post(); $widget_content .= '<li><a href="'.get_permalink() .'" rel="bookmark">'. get_the_title() .'</a></li>'; endwhile; $widget_content .= '</ul>'; // return the content you want displayed return $widget_content; } //function to setup widget function add_dashboard_widgets() { // create a dashboard widget called "private_page_menu_dashboard_widget" with the title "Private Pages Menu" and call our display function to draw it wp_add_dashboard_widget('private_page_menu_dashboard_widget', 'Private Pages Menu', 'display_dashboard_widget' ); } // finally we have to hook our function into the dashboard setup using add_action add_action('wp_dashboard_setup', 'add_dashboard_widgets'); |
The only problem with wp_add_dashboard_widget is that it doesn’t allow you to define where on the dashboard the widget is placed. Instead it just places the box at the bottom of the left hand side in the ['normal']['core'] array.
I want my private page menu to display at the top on the right hand side of the dashboard, so I am going to add a few more lines to add_dashboard_widgets() to shuffle the boxes around the way I want them. This will be overridden by user settings if the boxes are dragged around, but insures that my authors and editors see the box in an obvious position when they first login.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | function add_dashboard_widgets() { // don't forget the global to get all dashboard widgets global $wp_meta_boxes; // create a dashboard widget called "private_page_menu_dashboard_widget" with the title "Private Pages Menu" and call our display function to draw it wp_add_dashboard_widget('private_page_menu_dashboard_widget', 'Private Pages Menu', 'display_dashboard_widget' ); // reorder the boxes - first save the left and right columns into variables $left_dashboard = $wp_meta_boxes['dashboard']['normal']['core']; $right_dashboard = $wp_meta_boxes['dashboard']['side']['core']; // take a copy of the new widget from the left column $my_widget = array('private_page_menu_dashboard_widget' => $left_dashboard['private_page_menu_dashboard_widget']); // remove the new widget from the left column unset($left_dashboard['private_page_menu_dashboard_widget']); // use array_merge so that the new widget is pushed on to the beginning of the right column's array $right_dashboard = array_merge($my_widget, $right_dashboard); // finally replace the left and right columns with the new reordered versions $wp_meta_boxes['dashboard']['normal']['core'] = $left_dashboard; $wp_meta_boxes['dashboard']['side']['core'] = $right_dashboard; } |
I hope you find these tricks as useful as I do!
Resources
- Power Tips for WordPress Template Developers: Reloaded – more cool back end optimisations, hacks and tweaks
- Register Plus WordPress Plugin – customise your registration, login and admin areas
- Dashboard Widgets API – more info on adding and removing dashboard widgets
A Note on Snippets: When customising a CMS such as WordPress it is often the simplest pieces of code which are the hardest to either find or remember. These snippets are placed here for my own reference and will hopefully be useful to others. If you find them useful or have any suggestions, please let me know.




30th Jun
Laura Kalbag says:
Very useful! WordPress can get a bit messy with all the plugin authors adding their own feeds.
Definitely adding this to the bookmarks list.
24th Aug
Matt says:
Great post! Worked like a charm. Can I lose the “add new” under Pages drop down for editors? I don’t want them to have the ability to create new pages.
24th Aug
ErisDS says:
You can, and I have a code sample somewhere. I’ll look at whipping together a post on it this week.
30th Aug
ErisDS says:
@Matt I’ve put together a post on removing the “add new link” – http://bit.ly/d3o3nI
22nd Sep
mongobread says:
Definitely a winner, however I was thinking if it’s possible to tidy dashboard by user instead of role?
30th Sep
pluc says:
Great article ErisDS. I have a client who requested custom dashboard items – actually a full dashboard replacement. Your article gave me everything I needed to do that without having to look everything up myself. Thanks a lot!
6th Jan
Dave says:
You could always use this plugin http://wordpress.org/extend/plugins/dashboard-heaven/
It allows you to set the visibility of individual widgets on the dashboard by user/role/capability
Cheers,
3rd Feb
Tony says:
This is absolutely brilliant. I can’t believe I had to read through so many different online entries that only offered mild suggestions before I had the good fortune of tracking this one down.
Now I’ve managed to clean up my client’s dashboard and then, using ‘iframes’ of all things, include access to a custom built application they use to run their league. The client is a soccer league and they have to continually go to different places to access their information and run their league in addition to logging into their WP-Admin to access the site’s CMS. With your post I’ve been able to dump all the other information that they don’t want, add in my own dashboard widget and then display their league management tool. Perfect.
Thank you for this.
12th Mar
Website Design, Lake Geneva, WI says:
Oh, this is good stuff. Very good, indeed.
Karl
28th Apr
20 Snippets and Hacks to Make Wordpress User-Friendly for your Clients pinged back:
[...] [...]
30th Apr
Bst Wordpress Hacks to Make User Friendly | 39Articles pinged back:
[...] Source → [...]
25th May
Matth says:
OMG! Thank you.
I searched far and wide for a say to simply MOVE my excerpts box over to the right column, for no good reason, just my personal preference.
“if the boxes are dragged around” <—- !!! what really?
So I tried it and sure enough, that's all I needed to do. This seems like undocumented feature, so thanks for bringing it to my attention.
26th Aug
Er.Sandeep Pal Singh Grewal says:
Q1-I want to Remove tools option like posts in user admin area ? What is solution to this ,is solution is easy or difficult Please give me that?
7th Sep
Internet Marketing Company Toronto says:
This is great! Now I can easily customize my WordPress admin page to specific roles or group of people. I just hope I wont mess up the settings.
-John Sumner
30th Oct
9 Snippets to Make WordPress User-Friendly (part 2) | jQuery4u pinged back:
[...] This code will get rid of the ‘Incoming Links’ widget for authors and editors and then clean up some of the other boxes for everyone. Source [...]
26th Dec
mahabub says:
thanks for share this coding.