Making and management Dashboard widgets

What is a Dashboard widget? In WordPress, Dashboard widgets are the informational section that is available at your website admin dashboard. WordPress widget is a small block that performs a specific function. You can have widgets on the frontend as well on the backend admin of the website. The widgets which are available on the…

What is a Dashboard widget?

In WordPress, Dashboard widgets are the informational section that is available at your website admin dashboard. WordPress widget is a small block that performs a specific function. You can have widgets on the frontend as well on the backend admin of the website. The widgets which are available on the dashboard are known as WordPress dashboard widgets.

Creating a Custom Dashboard Widget manually

We will add a Custom Dashboard Widget and show some of the posts which are been published.

We can create a new one manually using custom coding.

Registering dashboard widget

To register the dashboard widget we use a built-in function.

wp_add_dashboard_widget (
    'wk_dashboard_add_widget',
    'Custom Dashboard Widget',
    'wk_dashboard_widget_function'
);
add_action(  'wp_dashboard_setup', 'wk_dashboard_add_widget'  );

Creating a function that handles the content display

Let’s add a function for this named in the previous step as ‘wk_dashboard_widget_function‘.

function wk_dashboard_widget_function() {
    global $post;
    $args = array( 'numberposts' => -1 );
    $myposts = get_posts( $args );
    display_post( $myposts );
}

Calling a function to display the posts         

The step includes setting up the posts on the widget.

function display_post( $posts ) {
    ?>
    <table class="wk-table">
        <tr class="wk-tr">
	    <th class="wk-th" ><h2>Title</h2></th>
	    <th class="wk-th" ><h2>Author</h2></th>
        </tr>
        <?php foreach ( $posts as $post ) { ?>
        <tr class="wk-tr">
	    <td class="wk-td">
                <a href="<?php get_permalink( $post->ID ) ?>"><?php echo get_the_title( $post->ID ); ?></a>
            </td>		
	</tr>
        <?php } ?>
    </table>

    <?php
}

After done, go to the dashboard. Then you can see it has been changed based on your code.

Creating and managing a Custom Dashboard Widget using the plugin

Step 1: Install and active Custom Dashboard widgets plugin.

Step 2: When you click on the Settings tab, you will see many sub-options. Click on the Dashboard Widgets to manage widgets on the Dashboard.

Dashboard widgets list -> when you click on the dashboard widgets option, you will see a table containing all the current links placed on the Dashboard of the WordPress site.

We have a View site, Profile, Posts, Media, Users, Pages, Plugins, and Settings as you can see in the following image.

Also In the second column, you can see the associated icons. You can set any icon you want just by clicking on it. There are hundreds of options available for you.

Then we have an associated links column. Here you can set a link to anywhere you want to redirect a user. You can also set links to custom URLs.

Step 3: Add More Dashboard Widget: If you want to add more Widgets to your Dashboard then click on Add More button to add them. See the below image.

Added row: When you click on the add more button, the new row will add to your dashboard list.

Later you can also change the given name on the new row.

You can change the name of your added row then click on the title text box of your added row, then change your widget name as given below image.

Regarding the checkbox and Delete feature:

Using the checkboxes, you can grant or not grant access to the link to various types of users on your WordPress site.

Delete Row: If you want to delete your newly added row from the list, click on the small Red Cross in the last column.

Finally, you can click the “Save” button or “Reset” as you want.

Reset Setting: If you want to create a new list or reset your settings, then click on the Reset to Defaults button that is available at the end of the page.

This is how you can set up a list of custom Dashboard widgets. These are not the advanced widgets that you get on a default WordPress dashboard. Instead, you get links to different parts of WordPress along with permission management. This is really good if you are running a small SaaS on your WordPress website.