
How to Create a Custom Dashboard Widget in WordPress
- March 13, 2017
- Leave a comment
WordPress provides a Widgets feature in order to create multiple dashboard widgets or you can say to enhance your Dashboard in minutes. Using WP Dashboard Widgets API, you can add new widgets to the administration panel. Following is the example of a customized Dashboard widget:
To add a custom Dashboard Widget, use the following code snippet in your functions.php file or custom add-on:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
add_action( 'wp_dashboard_setup', 'pt_add_dashboard_widget' ); /** * Add a widget to the dashboard. * * This function is hooked into the 'wp_dashboard_setup' action below. */ function pt_add_dashboard_widget () { wp_add_dashboard_widget( 'presstigers', //Slug __( 'PressTigers | Truth - Beauty - WordPress', 'presstigers' ), // Title. 'pt_dashboard_widget_function' // Display function. ); } |
Using wp_dashboard_setup hook, you can create a Dashboard Widget with its callback function. In the callback function, you can set the widget slug, title, and display function.
To list any WP posts, custom post types and custom content in your custom Widget, use the following display function in your functions.php file:
1 2 3 4 5 6 |
/** * Display Widget content here. */ function pt_dashboard_widget_function() { echo "Anything you imagine can be crafted for WordPress. Hire WordPress Developers for Dedicated, Fix bid & Hourly Development in WordPress & UI/UX."; } |
User Comments