How can I add notification bubble to WordPress admin menu

I want to show some notification in wordpress admin menu for new posts as we can find one when a new plugin update is available black circle comes to the plugin menu with a number in it.

Related posts

Leave a Reply

1 comment

  1. Edit the theme’s function.php and append these line of codes –

    add_action('admin_menu', 'notification_bubble_in_admin_menu');
    
    function notification_bubble_in_admin_menu() {
        global $menu;
        $newitem = get_number_of_new_post_by_type('post');
        $menu[11][0] .= $newitem ? "<span class='update-plugins count-1'><span class='update-count'>$newitem </span></span>" : '';
    }
    
    function get_number_of_new_post_by_type($type)
    {
        global $wpdb;
        return $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}withdraw WHERE wd_status=0;" ) );
    }