iBlognet

Custom Dashboard Widget For Specific User Roles

by Editor

wordpress2WordPress Dashboard controls the contents and settings of a blog. It’s easy to add a widget in WordPress Dashboard, if you want to post a notice to a specific group of users. It’s also useful if you’re a Theme Developer and want to add a specific widget about Theme support on the Dashboard. Adding a custom widget is simple. Just open your functions.php and add the following code:

[PHP]
if(current_user_can(‘subscriber’)){
add_action(‘wp_dashboard_setup’, ‘subscriber_dashboard_widgets’);
}
function subscriber_dashboard_widgets() {
global $wp_meta_boxes;
wp_add_dashboard_widget(‘custom_help_widget’, ‘WIDGET TITLE’, ‘custom_dashboard_widget’);
}
function custom_dashboard_widget() {
echo ‘<p>ADD YOUR MESSAGE HERE. ADD A PARAGRAPH TAG FOR A NEW LINE.</p>’;
}
[/PHP]

If you want to display the widget only to your contributors or authors change the word “subscriber” on line 1. You can change the widget title on line 6 and you can add your custom message on line 9.
Dashboard
Your contributor will see something like the above image. If you have any problem installing the code, just leave a comment below and I will help you out.

Article by »


Admin and Editor of iBlognet iBlognet has written 294 fantastic article(s) on iBlognet.


Author Connect »

1 Obasi Miracle

I implemented this few hours ago in one of my friend’s my blog to say the least your code worked like a charm.

One more thing how can I remove the gravatar part?

2 Sahil Umatia

Gravatar Part?? From where??

3 Nishadha

Thanks for this great article. I was looking to do something like this in some of my blogs for users with contributor rights. Hopefully I can use this code to implement this.

4 TrendyWp

This is working very well, Thanks

Comments on this entry are closed.

Previous post:

Next post: