Registering and building dashboard widgets

First, we have to register the dashboard widget by using the wp_dashboard_setup action, instead of the widgets_init we used on the frontend widgets. Consider the following code for the widget registration process:

add_action( 'wp_dashboard_setup', array( $this, 'dashboard_widgets' ) );public function dashboard_widgets() {  wp_add_dashboard_widget( 'wqkm_post_attachments', __('Post Attachments','wqkm'), array( $this, 'post_attachments_widget' ) );}

Inside the callback function, we use the wp_add_dashboard_widget function to register a new widget. The parameters for this function contain a unique widget ID, widget title, and the callback function. Then, we have to implement the function to display the ...

Get WordPress Development Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.