Skip to content

Instantly share code, notes, and snippets.

@besrabasant
Last active November 10, 2019 03:59
Show Gist options
  • Save besrabasant/02891855f519a013e5dd1668a6a68b97 to your computer and use it in GitHub Desktop.
Save besrabasant/02891855f519a013e5dd1668a6a68b97 to your computer and use it in GitHub Desktop.
Add notification bubble for to custom admin menu page

There are two classes used by WordPress to display the notification bubbles:

  • update-plugins
  • awaiting-mod

Your notifications have nothing to do with plugins, so it will be nicer to use the second class. You should change your function like this:

function contact_form_create() {
    $notification_count = 2; // Notification value

    add_menu_page(
        'Contact Forms',
        $notification_count ? sprintf('Contact Forms <span class="awaiting-mod">%d</span>', $notification_count) : 'Contact Forms',
        'manage_options', 
        'contact-form',
        'contact_form_page_handler'
    );
}

add_action('admin_menu', 'contact_form_create');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment