WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to add a count number to a option menu item in the admin sidebar. How is this done?

I found a similar post:

Modifying admin sidebar contents to show pending posts indicator

share|improve this question

If you mean like this enter image description here

Then here is an handy class to get it done very quickly:

* add_num_to_admin_menu
* @author Ohad Raz <admin@bainternet.info>
class add_num_to_admin_menu
    public $menus = array();
     * Class constructor
     * @author Ohad Raz <admin@bainternet.info>
     * @param array $args menu => number format
    function __construct($args = array()){
        if (!is_admin())return;
        $this->menus = $args;
        add_filter( 'add_menu_classes', array($this,'_Add_num'));
     * the actual function that adds the number to the menu
     * @author Ohad Raz <admin@bainternet.info>
     * @param  array $menu admin menu
     * @return array
    function _Add_num($menu){
        foreach ((array)$this->menus as $name => $number) {
            // loop through $menu items, find match, add indicator
            foreach( $menu as $menu_key => $menu_data ) {
                if( $name != $menu_data[2] )
                $menu[$menu_key][0] .= " <span class='update-plugins count-$number'><span class='plugin-count'>" . number_format_i18n($number) . '</span></span>';

        return $menu;
     * Add a number to a menu
     * @author Ohad Raz <admin@bainternet.info>
     * @param string $menu  menu to add the number to
     * @param int $number number to add
    function addMenuNum($menu,$number){
        $this->menus[$menu] = $number;


//create an instance of the class
$obj = new add_num_to_admin_menu();
//add a number to a menu node
//repeat as many times as needed
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.