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.
01.function remove_menus () {02.global $menu;03.$restricted = array(__('Dashboard'), __('Posts'), __('Media'), __('Links'), __('Pages'), __('Appearance'), __('Tools'), __('Users'), __('Settings'), __('Comments'), __('Plugins'));04.end ($menu);05.while (prev($menu)){06.$value = explode(' ',$menu[key($menu)][0]);07.if(in_array($value[0] != NULL?$value[0]:"" ,$restricted)){unset($menu[key($menu)]);}08.}09.}10.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.
1.function my_custom_login_logo() {2.echo '<style type="text/css">3.h1 a { background-image:url('.get_bloginfo('template_directory').'/images/custom-login-logo.gif) !important; }4.</style>';5.}6.7.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.
1.add_action('admin_head', 'my_custom_logo');2.3.function my_custom_logo() {4.echo '<style type="text/css">5.#header-logo { background-image: url('.get_bloginfo('template_directory').'/images/custom-logo.gif) !important; }</style>';6.}» 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.
1.if ( !current_user_can( 'edit_users' ) ) {2.add_action( 'init', create_function( '$a', "remove_action( 'init', 'wp_version_check' );" ), 2 );3.add_filter( 'pre_option_update_core', create_function( '$a', "return null;") );4.}» 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 yourfunctions.php file.
01.function example_remove_dashboard_widgets() {02.// Globalize the metaboxes array, this holds all the widgets for wp-admin03.global $wp_meta_boxes;04.05.// Remove the incomming links widget06.unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']); 07.08.// Remove right now09.unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);10.unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);11.unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);12.}13.14.// Hoook into the 'wp_dashboard_setup' action to register our function15.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.
01.function example_dashboard_widget_function() {02.// Display whatever it is you want to show03.echo "Hello World, I'm a great Dashboard Widget";04.}05.06.// Create the function use in the action hook07.function example_add_dashboard_widgets() {08.wp_add_dashboard_widget('example_dashboard_widget', 'Example Dashboard Widget', 'example_dashboard_widget_function');09.}10.// Hoook into the 'wp_dashboard_setup' action to register our other functions11.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.
1.function custom_colors() {2.echo '<style type="text/css">#wphead{background:#069}</style>';3.}4.5.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.
01.function my_admin_help($text, $screen) {02.// Check we're only on my Settings page03.if (strcmp($screen, MY_PAGEHOOK) == 0 ) {04.05.$text = 'Here is some very useful information to help you use this plugin...';06.return $text;07.}08.// Let the default WP Dashboard help stuff through on other Admin pages09.return $text;10.}11.12.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.
01.function slt_PHPErrorsWidget() {02.$logfile = '/home/path/logs/php-errors.log'; // Enter the server path to your logs file here03.$displayErrorsLimit = 100; // The maximum number of errors to display in the widget04.$errorLengthLimit = 300; // The maximum number of characters to display for each error05.$fileCleared = false;06.$userCanClearLog = current_user_can( 'manage_options' );07.// Clear file?08.if ( $userCanClearLog && isset( $_GET["slt-php-errors"] ) && $_GET["slt-php-errors"]=="clear" ) {09.$handle = fopen( $logfile, "w" );10.fclose( $handle );11.$fileCleared = true;12.}13.// Read file14.if ( file_exists( $logfile ) ) {15.$errors = file( $logfile );16.$errors = array_reverse( $errors );17.if ( $fileCleared ) echo '<p><em>File cleared.</em></p>';18.if ( $errors ) {19.echo '<p>'.count( $errors ).' error';20.if ( $errors != 1 ) echo 's';21.echo '.';22.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> ]';23.echo '</p>';24.echo '<div id="slt-php-errors" style="height:250px;overflow:scroll;padding:2px;background-color:#faf9f7;border:1px solid #ccc;">';25.echo '<ol style="padding:0;margin:0;">';26.$i = 0;27.foreach ( $errors as $error ) {28.echo '<li style="padding:2px 4px 6px;border-bottom:1px solid #ececec;">';29.$errorOutput = preg_replace( '/\[([^\]]+)\]/', '<b>[$1]</b>',$error, 1 );30.if ( strlen( $errorOutput ) > $errorLengthLimit ) {31.echo substr( $errorOutput, 0, $errorLengthLimit ).' [...]';32.} else {33.echo $errorOutput;34.}35.echo '</li>';36.$i++;37.if ( $i > $displayErrorsLimit ) {38.echo '<li style="padding:2px;border-bottom:2px solid #ccc;"><em>More than '.$displayErrorsLimit.' errors in log...</em></li>';39.break;40.}41.}42.echo '</ol></div>';43.} else {44.echo '<p>No errors currently logged.</p>';45.}46.} else {47.echo '<p><em>There was a problem reading the error log file.</em></p>';48.}49.}50.51.// Add widgets52.function slt_dashboardWidgets() {53.wp_add_dashboard_widget( 'slt-php-errors', 'PHP errors','slt_PHPErrorsWidget' );54.}55.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.
01.function customize_meta_boxes() {02.//retrieve current user info03.global $current_user;04.get_currentuserinfo();05.06.//if current user level is less than 3, remove the postcustom meta box07.if ($current_user->user_level < 3)08.remove_meta_box('postcustom','post','normal');09.}10.11.add_action('admin_init','customize_meta_boxes');» Source
hi everyone,
I am in the development of finalizing my website shopping. I’ve gone surfing many portals and for all time this [url=http://www.websitetraders.com/]websites for sale[/url] website appears secure. Anybody have any experience doing business with them?
Thanks every one for reading.
I’m looking forward to getting more information about this topic, don’t worry about negative opinions.
You have really great taste on catch article titles, even when you are not interested in this topic you push to read it
Hey
Really glad to get into this forum
It’s what I am looking for.
Hope to know more member here.
When was the last time you were driving down the digital highway and felt like you were shot by words?
Thanks for this great article! If you don’t mind, it’s featured and linked on our blog (just an excerpt)
Ya Sure Carry on…
Very useful little article. Thank you. I jumped into replacing my dashboard logo and didnt realize how easy it was. WP is truly awesome. One thing though, if you are using a child theme, the call to get_bloginfo(‘template_directory’) will return the parent themes directory, not the child themes.
For me this was easily fixed with replacing template_directory with stylesheet_directory, so:
get_bloginfo(‘stylesheet_directory’)
Cheers,
Afshin
I’d like to do some tweaks on a wordpress.com blog. Is that possible? It seems to me that it’s rather for wordpress.org blogs.
I know this if off topic but I’m looking into starting my own weblog and was wondering what all is needed to get set up? I’m assuming having a blog like yours would cost a
pretty penny? I’m not very internet smart so I’m not 100% certain. Any recommendations or advice would be greatly appreciated. Thank you
Hi, I do believe this is an excellent blog. I stumbledupon it
I may return once again since i have book marked it.
Money and freedom is the greatest way to change, may you be
rich and continue to guide other people.