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

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

1 Answer 1

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 <>
class add_num_to_admin_menu
    public $menus = array();
     * Class constructor
     * @author Ohad Raz <>
     * @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 <>
     * @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 <>
     * @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.