10 WordPress dashboard hacks

by Jean. 118 Comments -

The dashboard is a very important part of a WordPress blog. In fact, it allows you to control your posts, your blog design, and many more things. When building a site for a client, it is especially important to be able to control WP’s dashboard. In this article, let’s have a look at 10 extremely useful hacks for WordPress’ dashboard.

Remove dashboard menus

When building a WordPress blog for a client, it can be a good idea to remove access to some dashboard menus in order to avoid future problems such as the client “accidentally” deleting the custom theme they paid for.
Paste the following code in the functions.php file from your theme directory. The following example will remove all menus named in the $restricted array.

function remove_menus () {
global $menu;
		$restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('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)]);}
		}
}
add_action('admin_menu', 'remove_menus');

» Source

Define your own login logo

Although it doesn’t have any importance for the blog performance or usability, most clients will be very happy to see their own logo on the dashboard login page, instead of the classic WordPress logo.
The Custom admin branding plugin can do that for you, as well as the following hack that you just have to paste in your functions.php file.

function my_custom_login_logo() {
    echo '<style type="text/css">
        h1 a { background-image:url('.get_bloginfo('template_directory').'/images/custom-login-logo.gif) !important; }
    </style>';
}

add_action('login_head', 'my_custom_login_logo');

» Source

Replace dashboard logo with yours

Just as a client will love to see their own logo on WordPress login page, there’s no doubt that they’ll enjoy viewing it on the dashboard too.
Simply copy the code below and paste it to your functions.php file.

add_action('admin_head', 'my_custom_logo');

function my_custom_logo() {
   echo '<style type="text/css">
         #header-logo { background-image: url('.get_bloginfo('template_directory').'/images/custom-logo.gif) !important; }</style>';
}

» Source

Disable the “please upgrade now” message

WordPress constantly release new versions. Although for obvious security concerns you should always upgrade; disabling the “Please upgrade now” message on client sites can be a good idea because the client doesn’t necessarily have to know about this, this is a developer’s job.

One more time, nothing hard: paste the code in your functions.php, save it, and it’s all good.

if ( !current_user_can( 'edit_users' ) ) {
  add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );
  add_filter( 'pre_option_update_core', create_function( '$a', "return null;" ) );
}

» Source

Remove dashboard widgets

Introduced in WordPress 2.7, dashboard widgets can be pretty useful. For example, some can display your Google Analytics stats. Though, sometimes you don’t need it, or at least don’t need some of them.
The code below will allow you to remove WordPress’ dashboard widgets once you paste it in your functions.php file.

function example_remove_dashboard_widgets() {
	// Globalize the metaboxes array, this holds all the widgets for wp-admin
 	global $wp_meta_boxes;

	// Remove the incomming links widget
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);	

	// Remove right now
	unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
	unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
}

// Hoook into the 'wp_dashboard_setup' action to register our function
add_action('wp_dashboard_setup', 'example_remove_dashboard_widgets' );

» Source

Add custom widgets to WordPress dashboard

With the previous example, I showed you how easy it is to remove unwanted dashboard widgets. The good news is that creating your own widgets isn’t hard either.
The well-commented code below should be self explanatory. Just insert it in your functions.php, as usual.

function example_dashboard_widget_function() {
	// Display whatever it is you want to show
	echo "Hello World, I'm a great Dashboard Widget";
} 

// Create the function use in the action hook
function example_add_dashboard_widgets() {
	wp_add_dashboard_widget('example_dashboard_widget', 'Example Dashboard Widget', 'example_dashboard_widget_function');
}
// Hoook into the 'wp_dashboard_setup' action to register our other functions
add_action('wp_dashboard_setup', 'example_add_dashboard_widgets' );

» Source

Change WordPress dashboard colors

If you ever wanted to be able to change WordPress dashboard colors (as well as font or even display) without having to edit WordPress core files, you’ll like this hack for sure.
The following example features a basic style change (grey header is replaced by a blue one) but you can easily add as many styles as you wish within the <style> and </style> tags.

function custom_colors() {
   echo '<style type="text/css">#wphead{background:#069}</style>';
}

add_action('admin_head', 'custom_colors');

Provide help messages

If you’re building a site for a client and they have some problems with some parts of the dashboard, a good idea is to provide contextual help to the client.
The following hack will allow you to add a custom help messages for the blog admin. As usual, you only have to paste the code into your functions.php file.

function my_admin_help($text, $screen) {
	// Check we're only on my Settings page
	if (strcmp($screen, MY_PAGEHOOK) == 0 ) {

		$text = 'Here is some very useful information to help you use this plugin...';
		return $text;
	}
	// Let the default WP Dashboard help stuff through on other Admin pages
	return $text;
}

add_action( 'contextual_help', 'my_admin_help' );

» Source

Monitor your server in WordPress dashboard

WordPress dashboard API allow you to do many useful things using dashboard widgets. I recently came across this very useful code: a dashboard widget that allows you to monitor your server directly on WordPress’ dashboard.
Paste the code in your functions.php file, and you’re done.

function slt_PHPErrorsWidget() {
	$logfile = '/home/path/logs/php-errors.log'; // Enter the server path to your logs file here
	$displayErrorsLimit = 100; // The maximum number of errors to display in the widget
	$errorLengthLimit = 300; // The maximum number of characters to display for each error
	$fileCleared = false;
	$userCanClearLog = current_user_can( 'manage_options' );
	// Clear file?
	if ( $userCanClearLog && isset( $_GET["slt-php-errors"] ) && $_GET["slt-php-errors"]=="clear" ) {
		$handle = fopen( $logfile, "w" );
		fclose( $handle );
		$fileCleared = true;
	}
	// Read file
	if ( file_exists( $logfile ) ) {
		$errors = file( $logfile );
		$errors = array_reverse( $errors );
		if ( $fileCleared ) echo '<p><em>File cleared.</em></p>';
		if ( $errors ) {
			echo '<p>'.count( $errors ).' error';
			if ( $errors != 1 ) echo 's';
			echo '.';
			if ( $userCanClearLog ) echo ' [ <b><a href="'.get_bloginfo("url").'/wp-admin/?slt-php-errors=clear" onclick="return confirm(\'Are you sure?\');">CLEAR LOG FILE</a></b> ]';
			echo '</p>';
			echo '<div id="slt-php-errors" style="height:250px;overflow:scroll;padding:2px;background-color:#faf9f7;border:1px solid #ccc;">';
			echo '<ol style="padding:0;margin:0;">';
			$i = 0;
			foreach ( $errors as $error ) {
				echo '<li style="padding:2px 4px 6px;border-bottom:1px solid #ececec;">';
				$errorOutput = preg_replace( '/\[([^\]]+)\]/', '<b>[$1]</b>', $error, 1 );
				if ( strlen( $errorOutput ) > $errorLengthLimit ) {
					echo substr( $errorOutput, 0, $errorLengthLimit ).' [...]';
				} else {
					echo $errorOutput;
				}
				echo '</li>';
				$i++;
				if ( $i > $displayErrorsLimit ) {
					echo '<li style="padding:2px;border-bottom:2px solid #ccc;"><em>More than '.$displayErrorsLimit.' errors in log...</em></li>';
					break;
				}
			}
			echo '</ol></div>';
		} else {
			echo '<p>No errors currently logged.</p>';
		}
	} else {
		echo '<p><em>There was a problem reading the error log file.</em></p>';
	}
}

// Add widgets
function slt_dashboardWidgets() {
	wp_add_dashboard_widget( 'slt-php-errors', 'PHP errors', 'slt_PHPErrorsWidget' );
}
add_action( 'wp_dashboard_setup', 'slt_dashboardWidgets' );

» Source

Remove dashboard widgets according to user role

If you’re owning a multi-user blog, it may be useful to know how to hide some dashboard widgets to keep confidential information in a safe place.
The following code will remove the postcustom meta box for “author” (role 2). To apply the hack on your own blog, just copy the code below and paste it in your functions.php file.

function customize_meta_boxes() {
     //retrieve current user info
     global $current_user;
     get_currentuserinfo();

     //if current user level is less than 3, remove the postcustom meta box
     if ($current_user->user_level < 3)
          remove_meta_box('postcustom','post','normal');
}

add_action('admin_init','customize_meta_boxes');

» Source

Comments (118) - Leave yours

  1. Sebastian Schertel said:

    Hey Jean-Baptiste,

    cool hacks. I hope you have some more dashboard hacks in the future. These seem very useful and i’ll definetly use them for some client work in the future. Right now i find it very interesting (and i hope that future WP updates or plugins will make the job even easier).

    When i see all this cool hacks and themes and just everything i am thinking of becoming a programmer instead of a marketer to fulfill my theme dreams. :)
    Or hiring one exclusive programmer. :)

    Thanks and enjoy your time!

  2. Blogger Den said:

    It’s crazy to see WordPress growing like a weed! I remember back when WordPress was released in beta still trying to kick out all of the bugs, and now look how far it’s gotten. These are some great hacks and I appreciate sharing them on the blog – I look forward to your next post

  3. Martin Lynge said:

    I rarely come across articles on customisation of the WP dashboard. Great article only 1 out of 10 hacks I didn’t find any need fore!
    This stuff can really take your themes or site to the next level.

    Happy New Year

  4. Jamie Simmerman said:

    I found your site through a Google search for WP plugins to alter the dashboard. I’m loving it and will be back to read more! What I was looking for, was a dashboard widget that lets you post announcements in the dashboard. We have several authorized users who post at intervals, and I wanted something to relay info about changes to the site, tips, etc.

    Do you know if such a creature exists?

  5. Les said:

    I am sure these will help a lot of people, but I have never seen as much procedural horse manure in my life – that is just the problem with WP, it is just a bunch of procedural functions pasted together.

    I do not expect a lot of people to understand where I am coming from, where my background is software engineering – proper software development using object oriented methodologies, etc.

    WP is building up a big mess for it’s self as I have not in the years of WP seen any serious improvements on the codebase, and now we have members of the public making contributions to a codebase who are not particularly from a development background.

    Hell, please continue as the day WP goes down the crapper moves ever closer! Well done.

    • Aaron said:

      The crapper appears to be miles away, considering that WP is the pretty much the dominant blogging platform.

      OO is great, but when you’re on the web it doesn’t always make much sense, since the web is a stateless environment. I know that .NET tries to remedy this by serializing in between postbacks and using asynchronous calls, but honestly, that’s gopher hunting with a stinger missile.

      Procedural programming makes sense in the platform — it’s more lightweight and more flexible. And clearly, since so many programmers that aren’t even worthy of standing in your shadow are able to code very workable plugins / themes for it, the approach works fine.

      That said — WP 3.0 offers a bit more modularity and hook-based programming that make it a little more structured and robust — but AFAIK it is still largely procedural (some back-end processes aside).

  6. Jean-Baptiste Jung said:

    @Les : You’re probably a better programmer than me, but still, I don’t see what’s wrong with procedural programming in WP.
    If you have OO equivalents for the functions above, do not hesitate to share them with us.

  7. Craig Parker said:

    That server monitor one sounds ace, gonna give that a try now!

    Not really made any use of the dashboard since they implemented it so maybe this will be a good chance to start messing.

  8. Randy said:

    Another helpful post! I have been ‘hiding’ things from the clients by simply adding some styling to the functions.php such as:
    li#menu-appearance { display:none;}
    The above hides the Appearance area and so on.
    Firebug shows you all you need to know.
    You can also conditionally check the user level with get_currentuserinfo(); to see who sees what.
    Thanks!

  9. Dave Holowiski said:

    Wow this is great, it never occurred to me to hack my dashboard, but now I can see the possibilities, especially when setting up a wordpress site for customers. It would be great to display my phone number under a “Support” widget on the dashboard!

    Now that you mentioned Google Analytics, I would love! to have my analytics displayed in a dashboard widget. Any idea how? I bet there must be a plugin for that.

  10. Thomas Plastino Martin said:

    Hey, thanks for the hacks! I am most definitely going to be implementing some of these.

    I suppose that if you wanted to make it more OO, you would. I’d think that instead of whining about it, one would do something about it.

  11. Cosmin said:

    Any idea how to remove default panels such as Trackbacks or Discussion in the Write Post page?

    I’ve seen it done somewhere through functions.php and it was very similar to removing the wp generator metatag (remove_action(‘wp_head’, ‘wp_generator’); ), but now I can’t find it anywhere.

    Please help anyone :)

    • Vusi said:

      Have you found a solution for removing Trackbacks or Discussion in the Write Post page?, i am on the hunt for this solution

  12. tommy said:

    COOL!
    Another helpful post! I have been ‘hiding’ things from the clients by simply adding some styling to the functions.php
    love your blog!

  13. George Serradinho said:

    Thanks for the hacks, sure to have a look at them. I would say that the 1st one would be ‘Remove dashboard widgets according to user role’, I think thats one I will impliment soon.

  14. oli said:

    Hey Jean Baptiste,

    this tips are exactly the things i’ve looked for.

    I enjoy every day to read your blog and the CWC Blog too.

    Don’t stop your working with this :-)

  15. tom said:

    @Peter Steen Høgenhaug

    This should do what you need:

    if($current_user!=’yourusername’){
    add_action(‘admin_menu’, ‘remove_menus’);
    }

    http://codex.wordpress.org/Function_Reference/wp_get_current_user

  16. christopher said:

    wow… thanks for those tips. it’s a great way to keep pesky people from messing with WP too much. It’s good to keep everything as simple as possible for some clients… I’m sure you know what I mean.

  17. Thomas Hubbard said:

    For those who’d like to remove dashboard widgets according to the user’s role (eg, Subscriber or any other role), I think this will do the trick…

    if ( is_user_logged_in() ) {
    $userRole = ($current_user->data->wp_capabilities);
    $role = key($userRole);
    unset($userRole);
    switch($role) {
    case ‘subscriber’:
    case ‘anotherole’:
    add_action(‘admin_menu’, ‘remove_menus’);
    break;
    default:
    break;
    }
    }

  18. Erik Dwelly said:

    Hello. QUESTION: I love the idea of editing the admin panel for selected users. Waht I need to be able to do is allow a client to EDIT posts and pages, but not allow them to ADD NEW posts and pages.
    Can someone please assist me with this or point me in the right direction. Any help would be greatly appreciated.
    Thanks ~ Erik

  19. Ramsey said:

    Great article! I plan on playing with several of the above hacks.

    But for now, I have a general question. I’d like to make my *own* hack. (Basically, I want to edit some text in one of the admin files.) So, how would I do that without editing core files? Copy and paste the function into my functions.php file? I tried that, and so far, it doesn’t seem to be working…

  20. Robert Felty said:

    Ramsey,

    You can only overwrite core functions that are in pluggable.php. Many core functions use filters though, so you can add a filter to one of those to manipulate the output that it returns.

  21. Ramsey said:

    Robert, interesting! I guess you learn something new everyday. So, if the core function that I am wanting to work with has a filter, how do I figure that out? Any good articles or blog posts out there? (I’m a frontend designer, not a backend developer. ;) ) Thanks!

  22. Maliko said:

    Excellent tips for wordpress, i like the concept of removing the delete menu from Dashboard as it is important to keep ti away from novice as it will mess all the things. great job bravo.

  23. Jim said:

    Great hacks! Many I’d love to implement for clients, but… I’m getting some errors.

    Sorry to be a newbie about this… but I keep getting php error messages when I copy and paste the code. Are there any special tricks to this? Any particular place the code needs to go? Do you need to add extra to the code?

    Currently running 2.9.1… is there something about this version that would preclude me from using these hacks?

  24. Bruno Bichet said:

    Salut, merci encore pour cette très bonne liste très utiles. J’ai juste une petite question : comment supprimer le tableau de bord de “cforms” car $restricted = array(__(‘cforms’) ne donne rien (c’eut été trop facile ;) Merci d’avance !

    • Jean-Baptiste Jung said:

      Hello Bruno, je n’utilise pas cForms mais je pense qu’il faut récupérer le nom qui est utilisé pour la création du menu et utiliser ce nom dans $restricted = array(__(‘le_nom_utilise_par_cforms’).

  25. Jeff Archibald said:

    Great, great article. As someone who uses WP as a CMS, these hacks are invaluable. Nice to know we don’t always have to rely on the sometimes-unreliable plugin version – we can control this stuff ourselves. Kudos!

  26. Andy said:

    These are amazing thank you so much…I didn’t think any of this was possible and my clients will love me for finding them!!

  27. Rev. Voodoo said:

    Cool article. I’ve been making my own themes since starting WP….but always felt I was relying on plugins a bit too much. The past couple of days I’ve been cruising the google machine for things to do with my functions.php file, and you definitely helped me add some neat tricks!

  28. devashish said:

    Very useful article.. i was looking for sumthing similar to “Remove dashboard widgets”. Can the code be update so the widgets are not removed for administrator and editor role users?

    • Gautham said:

      I love these dashboard hacks, I always wondered if could change the traditional look of dashboards especially because i have a lot of user-driven community.

  29. karl said:

    Great dashboard tips, I have started playing with wordpress as a CMS for multiple users and it seems pretty good.

    I do have one question, maybe you have shared the hack before but I can’t find it any where, how can I hide the commenter ip address and e-mail address from the edit-comment.php dashboard page for authors? so basically administrator can see all but authors just need to see the author’s name and that’s it.

    Anyway clues?

    Thanks

      • Carlos said:

        @Hamed and @Kirsten, not a big fan of ‘disabling’ elements using CSS but I haven’t been able to find an alternative that works. So here’s what I’m currently using (hope you can copy code here):

        function hide_help() {
        echo ‘
        #contextual-help-link-wrap { display: none !important; }
        ‘;
        }
        add_action(‘admin_head’, ‘hide_help’);

  30. Daniel said:

    Great tips! Particularly the custom login icon. WP really should have this one covered. Would not wp would do away with it completely but be able to upload your own custom image below it near it on top of it etc.

    How i can i custom my web sites sidebar to look the same as the WP Dashboard i actually like the look of the dashboard is there a theme that does something similar that i could borrow some template code from? I also need to make one “home page” with three columns for snippets of everything in the site.

  31. neewis said:

    Hii Jean!
    Great Article but some how none of them are working. I am using 2.9.2 version and I dont know this is because of that. it would be great if you can give me solution to this.
    Thanks
    Neewis

  32. Nick said:

    Nice list – in particular disabling the “please upgrade now” message is golden! Have had clients upgrade their sites and all the plugins stop working before :S

    Nick

  33. Bill said:

    Nice, nice,… no not nice… stupendous! How come every time I go searching for code, I {virtually} 99.9997% of the time I end up on CWC… sheesh! Thanks JBJ ;) .

  34. Suneel said:

    Help messages tip was awesome and served the purpose of reducing the documentation to my client because he can see the tip then and there itself.

    Thanks for the tip.

  35. Dave said:

    Nice! Will these hacks also trickle down to clients on my network? I need these to show in their dashboards as well.

  36. dbm said:

    Hey!

    Great tips but using wp 3.0.1 the help menu hack is not working. An empty screen is shown when you click on the “help” tab. Any suggestions?

  37. David said:

    Great hacks guys. I only knew a few of these.

    Unfortunately I couldn’t find the hack I was looking for.

    The backend search in my clients website has stopped working, so searching for pages results in ‘not found’ every time. I was hoping to be able to get the list of pages to show all, or at least more, pages on each screen, rather than having to click through to see them all. I thought this would ease the pain until I figure out why the search isn’t working.

    Unfortunately every search I do on WordPress searches only bring up results about front end search.

  38. Hamed said:

    Is it possible to remove the logout link from admin pages or have it redirect to a certain page without modifying the core pages?

    I have a custom ajax login and do not use the wp-login page.

  39. Joe said:

    The “Disable ‘Please update now’ message’ hack did not work for me (WordPress 3.0). I had to use this:

    add_action( ‘admin_init’, create_function( ‘$a’, “remove_action( ‘admin_notices’, ‘update_nag’, 3 );” ), 2 );

    Thanks for the tip, though, since I would not have found that hook without trying yours first!

  40. Mark said:

    Has anyone been able to get the list of pages to *show all*, or at least more, pages on each screen, rather than having to click through to see them all?

  41. Ran said:

    Hi,

    Thanks for the hacks.

    I have some plugin-menu items which simply won’t get removed from showing up in my dashboard despite using the code in the functions file to remove various menu items from the dashboard.

    For example I have a menu item called “My Theme”. Any ideas on how I can remove these?

    Thanks.

  42. Sold Out Activist said:

    For a while now, it’s much easier to remove admin menus:

    add_action(‘admin_menu’, ‘remove_menus’, 999);
    function remove_menus () {
    remove_menu_page(‘edit.php’);
    remove_menu_page(‘link-manager.php’);
    remove_menu_page(‘edit-comments.php’);
    remove_menu_page(‘users.php’);

    remove_submenu_page(‘themes.php’, ‘theme-editor.php’);
    remove_submenu_page(‘themes.php’, ‘themes.php’);
    remove_submenu_page(‘plugins.php’, ‘plugin-editor.php’);
    }

  43. Fabio said:

    Great tips. One question though: instead of the custom_color function, is there a way to simply replace the style sheet? (or add another one)

    Thanks in advance!

  44. Tim said:

    I do have a question, can you customize or give guidance on how to customize the user end dashboard for a multi site installation.

    We only want the dashboard, user profile and themes nothing else.
    All you help is greatly appreciated.

    Thanks
    Tim

  45. Hemu said:

    Can you please tell me any plugin or code which allow me to add wordpress category and post directly from the wp quickpress

  46. Krishna said:

    Well that was really help post. But can you please tell me that which is the best alternative to the code : custom_color function, I really don’t understand that!

    • Jitender said:

      I’ve been making my own themes since starting WP… But always felt I was relying on plugins a bit too much. The past couple of days I’ve been cruising the Google machine for things to do with my functions.php file, and you definitely helped me add some neat tricks!

  47. Geet said:

    wow… thanks for those tips. it’s a great way to keep pesky people from messing with WP too much. It’s good to keep everything as simple as possible for some clients… I’m sure you know what I mean.

  48. Harsh said:

    Well that was really assist submit. Yet can you you should say to me that which is the greatest replacement for the particular code: custom_color perform, I seriously don’t be aware that! Nice work :D Great post, thanks. these will come in handy

  49. Sai said:

    Limit login access plugin is best plugin i think to protect the site from hacks, anyway you have listed some best hacks here :)

Leave a Reply

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

Please respect the following rules: No advertising, no spam, no keyword in name field. Thank you!