WordPress

How to Create a Custom Dashboard Widget in WordPress Admin

How to Create a Custom Dashboard Widget in WordPress Admin

What Is a Dashboard Widget?

When you log into WordPress, the first screen you see is the Dashboard — it includes widgets like “At a Glance” or “Quick Draft.” But did you know you can add your own custom widgets to this area?

This is great for:

  • Leaving welcome messages or instructions for clients
  • Showing custom stats or tips
  • Creating admin shortcuts

Step 1: Hook into wp_dashboard_setup

Paste the following into your theme’s functions.php file (or a custom plugin):


function my_custom_dashboard_widget() {
  wp_add_dashboard_widget(
    'custom_dashboard_widget',        // Widget slug
    '📌 Welcome to Your Dashboard',    // Title
    'custom_dashboard_widget_content' // Callback function
  );
}
add_action('wp_dashboard_setup', 'my_custom_dashboard_widget'); 

Step 2: Add Widget Content

Now define the function that outputs the content:


function custom_dashboard_widget_content() {
  echo '<p>Hi there! Here are a few quick links to get started:</p>';
  echo '<ul>
    <li><a href="' . admin_url('post-new.php') . '">Add New Post</a></li>
    <li><a href="' . admin_url('customize.php') . '">Customize Your Site</a></li>
    <li><a href="' . admin_url('plugins.php') . '">Manage Plugins</a></li>
  </ul>';
}

📌 Tip: You can replace this content with anything — client instructions, video embeds, contact buttons, etc.


Optional: Restrict Widget to Specific User Roles

Want to show it only to admins? Wrap your output in a condition:


function custom_dashboard_widget_content() {
  if (current_user_can('administrator')) {
    echo '<p>Admin-only dashboard note here.</p>';
  }
}

Styling the Widget (Optional)

To style your dashboard widget, enqueue an admin stylesheet:


function custom_admin_styles() {
  echo '<style>
    #custom_dashboard_widget ul li {
      margin-bottom: 5px;
    }
    #custom_dashboard_widget h2 {
      font-size: 16px;
    }
  </style>';
}
add_action('admin_head', 'custom_admin_styles');

Conclusion

Adding a custom dashboard widget is a simple way to personalize the WordPress admin area — especially useful for client sites, multi-author blogs, or your own workflow.

With just a few lines of code, you can provide shortcuts, display messages, or even integrate analytics widgets right into the admin dashboard.