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

 

65 Comments

  1. Posted December 28, 2009 at 4:56 pm | Permalink

    Nice one, I am going to use first logo & color hack for wordpress dashboard

    • Posted February 12, 2010 at 2:19 pm | Permalink

      There are plugins for most of these. No need to dig through code plus you have to re-edit the code each time you upgrade wordpress

      • Posted February 14, 2010 at 3:24 am | Permalink

        The functions file doesn’t get over-written during upgrades.

  2. Posted December 28, 2009 at 5:01 pm | Permalink

    help messages and the last tip saved my time,
    wiiiihaaa!

  3. Posted December 28, 2009 at 5:22 pm | Permalink

    Don’t edits to functions.php get overwritten during upgrades?

  4. Posted December 28, 2009 at 5:29 pm | Permalink

    @Dani : No, it doesn’t.

  5. Posted December 28, 2009 at 6:02 pm | Permalink

    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!

  6. Posted December 28, 2009 at 6:14 pm | Permalink

    Very handy article man

  7. Eddie
    Posted December 28, 2009 at 6:41 pm | Permalink

    Thanks for post, very good article :)

  8. Posted December 28, 2009 at 7:23 pm | Permalink

    These are some great wordpress hacks. These are going to help me out a lot with building blogs for clients. Thanks for all your work!

  9. Posted December 29, 2009 at 1:10 am | Permalink

    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

  10. Posted December 29, 2009 at 4:00 am | Permalink

    Awesome. It’s never really occurred to me that I could or even would change the Login & Dashboard logos. Now I’m going to go for it! Why not, eh?

  11. Posted December 29, 2009 at 5:35 am | Permalink

    These are some interesting and useful tips! I’ll put some of them to use, and see how well they work.

  12. Posted December 29, 2009 at 6:04 am | Permalink

    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

  13. Posted December 29, 2009 at 10:24 am | Permalink

    I really appreciate these types of articles……marvelous.

  14. Posted December 29, 2009 at 4:50 pm | Permalink

    It’s certainly a good list! Thanx! Been looking for this.

  15. Posted December 30, 2009 at 3:58 am | Permalink

    I’d love to find a hack that would display my Google Analytic info in the admin control panel for me to see instead of having to go to the GA site.

    Hint hint! :D

  16. Posted December 30, 2009 at 5:31 pm | Permalink

    Thanks for this – very helpful… I need to try out couple of them today.

  17. Posted December 30, 2009 at 6:06 pm | Permalink

    Hi there,

    For the hack on removing menus from the dashboard, is it possible to define for which users the menus should be removed?

  18. Posted December 30, 2009 at 6:13 pm | Permalink

    Yet another helpful article. I love this blog. :)

  19. Posted December 30, 2009 at 6:15 pm | Permalink

    @Peter Steen Høgenhaug : Sure you can. Have you checked the source of this snippets? It features some interesting examples.

  20. Posted December 30, 2009 at 6:32 pm | Permalink

    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?

  21. Posted December 30, 2009 at 7:10 pm | Permalink

    wow this cool.., thank you for the tutorial

    Happy New Year 2010

  22. Les
    Posted December 30, 2009 at 8:14 pm | Permalink

    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.

  23. Posted December 30, 2009 at 9:14 pm | Permalink

    @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.

  24. Posted December 30, 2009 at 9:20 pm | Permalink

    Heh, I guess the last snippet kind of tells me how to do that… Thanks, Jean-Baptiste!

  25. Posted December 31, 2009 at 10:11 am | Permalink

    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.

  26. Posted December 31, 2009 at 8:41 pm | Permalink

    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!

  27. Posted December 31, 2009 at 10:48 pm | Permalink

    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.

  28. Posted December 31, 2009 at 11:08 pm | Permalink

    Found it – Google Analytics Dashboard (it’s a plugin) displays your google analytics right on your dashboard woohoo!

  29. Posted January 1, 2010 at 9:28 pm | Permalink

    Thanks a lot for some of these dashboard hacks, definitely better than to have to download a plugin.

  30. Posted January 2, 2010 at 8:11 am | Permalink

    Wow.. I am going to give this a try with my Wordpress blog. I am too used to Blogger so I don’t know much about Wordpress.

  31. Posted January 2, 2010 at 1:44 pm | Permalink

    Thanks for the tip! I like it :-x

  32. Posted January 3, 2010 at 5:38 am | Permalink

    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.

  33. Cosmin
    Posted January 4, 2010 at 12:33 am | Permalink

    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 :)

  34. Posted January 4, 2010 at 11:00 am | Permalink

    A very nice article. Thanks for your hacks…

  35. Posted January 4, 2010 at 12:13 pm | Permalink

    thank you a lot for the tutorial, really useful!

  36. Posted January 4, 2010 at 1:32 pm | Permalink

    I am going to implement this color changes of dashboard.

  37. Posted January 4, 2010 at 8:36 pm | Permalink

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

  38. Posted January 5, 2010 at 8:38 am | Permalink

    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.

  39. Posted January 5, 2010 at 1:48 pm | Permalink

    Cool … Thanks for these tricks specially that Logo Change for Admin login.

  40. Posted January 6, 2010 at 11:53 pm | Permalink

    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 :-)

  41. Posted January 7, 2010 at 6:08 pm | Permalink

    @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

  42. Posted January 8, 2010 at 4:17 am | Permalink

    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.

  43. Posted January 10, 2010 at 10:47 pm | Permalink

    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;
    }
    }

  44. Posted January 11, 2010 at 8:30 pm | Permalink

    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

  45. Jacob Schulke
    Posted January 14, 2010 at 3:11 am | Permalink

    Thank you. Very helpful.

  46. Posted January 17, 2010 at 3:16 am | Permalink

    Thank’s for the tutorial

  47. Posted January 20, 2010 at 10:05 pm | Permalink

    Is there a way to pull in a custom RSS feed to the dashboard? To have a feed of tips coming in for a category of the developers blog.

  48. Posted January 21, 2010 at 5:44 am | Permalink

    Never mind. Didn’t know you could configure the built in RSS feed.

  49. Posted January 22, 2010 at 8:54 am | Permalink

    Nice hacks. I’m new to this wordpress hacking stuff. I started providing tutorials on it. If possible include this to your upcoming post [How To]Generate Goo.gl Short URL Without Any Worpress Plugin

  50. Posted January 22, 2010 at 5:34 pm | Permalink

    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…

  51. Posted January 23, 2010 at 5:21 am | Permalink

    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.

  52. Posted January 25, 2010 at 9:44 pm | Permalink

    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!

  53. Posted January 29, 2010 at 10:39 pm | Permalink

    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.

  54. Posted February 1, 2010 at 10:26 pm | Permalink

    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?

  55. Posted February 7, 2010 at 5:33 pm | Permalink

    Very useful information, thank you.

  56. Posted February 14, 2010 at 2:54 am | Permalink

    Its such a nice post. you must have worked very hard to get all these hacks and will be really handy and useful resource whenever needed. Good work. Thanks a lot.

  57. Posted February 14, 2010 at 2:26 pm | Permalink

    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 !

    • Posted February 14, 2010 at 3:09 pm | Permalink

      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’).

  58. Posted February 21, 2010 at 12:15 pm | Permalink

    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!

  59. Posted February 23, 2010 at 9:10 am | Permalink

    Perfect, just what I was looking for. Thanks in advance.

  60. Posted March 3, 2010 at 11:13 pm | Permalink

    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!!

  61. Posted March 13, 2010 at 11:49 am | Permalink

    Incredibly useful! Thanks a ton.

  62. Posted March 19, 2010 at 1:39 pm | Permalink

    Very nice blog, I have just bookmarked this article, I will need a while to understand the codes as a beginner, Thanks

8 Trackbacks

  1. By How to remove menus in WordPress dashboard on January 4, 2010 at 8:52 am

    [...] to hungred for this very useful trick! This recipes was previously featured in Cats Who Code 10 WordPress dashboard hacks [...]

  2. [...] статья является переводом, оригинал можно прочесть тут. tweetmeme_url = [...]

  3. [...] Lukemalla Wordpressin Codexia löytyy aika suoraan ohje asian käsittelyyn. Myöskin esim. CatsWhoCode.com- sivuilta löytyy asiaa käsittelevä blogi- teksti. [...]

  4. [...] 10 WordPress dashboard hacks [...]

  5. By links for 2010-02-07 on February 7, 2010 at 10:01 pm

    [...] 10 WordPress dashboard hacks (tags: wordpress dashboard) [...]

  6. [...] à l’emploi) pour mettre l’administration de votre blog Wordpress à vos pied ? Voici 10 WordPress dashboard hacks proposés par Cats Who Code membre du Smashing Network depuis peu. Au menu [...]

  7. By 10 WordPress dashboard hacks « Bring It on February 19, 2010 at 9:53 am

    [...] CatsWhoCode. 0 [...]

  8. By Segnalibri al 20.02.2010 ‹ Ubuntu block notes on February 21, 2010 at 3:59 am

    [...] 10 WordPress dashboard hacks [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting

  • Smashing Network
WordPress Appliance - Powered by TurnKey Linux