Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How do I add the “orange counter” next to a Custom Post Type?

I believe that the only sensible place to rename a menu item is the add_menu_classes filter hook.

It has a different destiny, but I can’t see any other place.
Hook passes an array of first-level menu items as a parameter to the function.
The array elements look like this:

$menu = [
    5 => Array (
        [0] => 'Menu title'
        [1] => 'capabilities'
        [2] => 'menu_slug' // e.g. edit.php | edit.php?post_type=page | edit.php?post_type=cpt_slug 
        [3] => 'Page title'
        [4] => 'css classes'
        [5] => ??
        [6] => 'dash-icon'
    ),
    70 => Array (
        [0] => 'Users'
        [1] => 'list_users'
        [2] => 'users.php'
        [3] => ''
        [4] => 'menu-top menu-icon-users'
        [5] => 'menu-users'
        [6] => 'dashicons-admin-users'
    ),
]

You can add badge with number by editing the menu item title, which is at index [0].

add_filter( 'add_menu_classes', 'se414500_menu_classes' );

function se414500_menu_classes ($menu)
{
    // --- v1 ---
    $my_counter = count( $something );
    foreach($menu as &$item)
    {
        // use menu_slug of your item
        if ($item[2] != 'edit.php?post_type=my_cpt_slug')
            continue;

        $item[0] .= sprintf(
            '<span class="update-plugins count-%s"><span class="update-count">%s</span></span>',
            $my_counter,
            number_format_i18n( $my_counter )
        );
    }
    // --- v2 ---
    // foreach($menu as &$item)
    // {
    //     // use menu_slug of your item
    //     if ($item[2] == 'edit.php?post_type=my_cpt_slug') {
    //         //
    //         // get the value to display next to the name
    //         $my_counter = count( $something );
    //
    //         $item[0] .= sprintf(
    //             '<span class="update-plugins count-%s"><span class="update-count">%s</span></span>',
    //             $my_counter,
    //             number_format_i18n( $my_counter )
    //         );
    //     }
    // }

    return $menu;
}

Related Posts:

  1. Query all posts where a meta key does not exist
  2. Can the Next/Prev Post links be ordered by menu order or by a meta key?
  3. what is the correct way to compare dates in a WP query_posts meta_query
  4. Advanced search form with filters for custom taxonomies and custom fields
  5. Meta query with boolean true/false value
  6. Get post with multiple meta keys and value
  7. Correctly delete posts with meta and attachments [duplicate]
  8. Storing revisions of metadata for custom post type
  9. Custom field values deleted when trashing custom post type
  10. How to get all custom fields of any post type
  11. Update CPT meta data using REST API
  12. Admin Area Custom Type Search By Meta Fields Without Title & Content
  13. Echo all meta keys of a custom-post TYPE
  14. Custom Post type – how to get checkbox to update meta field to null
  15. How can I filter posts by post_parent in the admin?
  16. How do I Paginate Search Results for Custom Post Types?
  17. How to Make an admin_notices Message That Disappears Once the User Leaves That Particular Page?
  18. Ordering posts having multiple post-meta date fields
  19. Custom Post Type with Input fields to seperate table on database.
  20. How do I remove all the metaboxes for a custom post type?
  21. Custom Queries: Joining On Meta Values From Two Custom Post Types
  22. Gutenberg how to make attribute to save to meta
  23. How to programmatically create a connection with [Plugin: Posts 2 Posts] on cpt publish?
  24. Post metadata deletes itself
  25. How to create a mini directory in WordPress?
  26. How Can I save multiple records in same meta key?
  27. Get all posts from custom post type and insert in select input as metabox
  28. Detect meta value changes when post is updated (post_updated)
  29. Search everything (posts, pages, tags, cpt, meta)
  30. Admin to user notices – best practices?
  31. Permalinks using event date (year & month) instead of publication date
  32. Custom Post Type: Set post_title equal to a custom post type field
  33. I can’t set meta_key in my custom post type query
  34. Grossly inefficient wordpress loops!
  35. Compare 3 custom fields and sort by oldest
  36. How Do I Use WP_Query to Run This Database Query as Search Result?
  37. WordPress Admin Panel search posts with custom post meta values along with title
  38. Creating a custom post type upon registration
  39. How to Update post status using meta data in Custom post TYpe
  40. Rest Api v2 orderby meta_key in custom post type
  41. bulk Update post_meta with default values
  42. Reason action hook won’t work with update_post_meta from frontend form? Alternative?
  43. Can’t sort order of wp_query with 2 meta keys
  44. Showing Meta Data for Custom Post Types?
  45. How to get source of custom meta image?
  46. Having trouble with custom post type / meta box
  47. Query for posts from any post type but only add instock products
  48. How can I include meta box content when searching?
  49. update a post meta from a single table cell TablePress
  50. update custom post type meta from a shortcode
  51. Custom Meta Boxes – Nonce Issue – Move to trash issue
  52. Displaying Meta Box Image
  53. Custom post type category not displaying in custom post type
  54. How to make custom post meta wp_editor translatable?
  55. Automatically adding meta data to posts or multiple query help
  56. How to keep a check box in custom meta box for custom post type checked by default for add new post?
  57. How to add multiple featured image in meta box in post editor?
  58. Show admin help message across custom post type parent and child posts
  59. Show metabox in custom-post-template depending on taxonomy term?
  60. How to add notification in the sidebar of the administration panel when a Custom post type is created? [duplicate]
  61. ACF Upload Image in repeater from front-end with custom form? – add_post_meta()
  62. update_post_meta() whenever custom post type is updated
  63. Formatting custom meta box date from YYYY/MM/DD to a more readable alternative
  64. Trigger “unsaved changes” dialog for custom post meta changes
  65. Using date stored as custom field to filter posts displayed in admin
  66. How to rewrite CPT-Permalinks the correct way (incorporating meta-box-data)?
  67. Rich Custom Field for Custom Post type not saving
  68. Add auto increment value to custom meta
  69. Custom post type submenu sorted by specific meta_key & meta_value
  70. Return only custom post types for the page, not all
  71. Change the contents of a dropdown through the admin panel?
  72. Advanced search form with filters for custom taxonomies and custom fields
  73. Retrieve post data via WPDB class
  74. Top 30 Songs using Custom Post Type
  75. Advice Needed for Post Meta Database Efficiency
  76. fetch meta fields inside a widget
  77. Querying meta values within an array
  78. Create action running on trashed_post hook to modify post_meta value
  79. Post AND page parameter for WP function
  80. Random meta field from specific custom post type
  81. Custom post type – update_meta not working
  82. why get_post_meta is returning 0?
  83. Custom Post Type meta value is being saved in array, instead of just the string (as value)
  84. Save post_parent in a custom post type
  85. Custom Form Data save after Login User
  86. How to display Author Profile based on Custom field value
  87. Use a Variable in update_post_meta as the $meta_key
  88. Automatically add custom taxonomy when meta value gets to a set number or beyond
  89. Display a list of posts whose meta field values are equal to the ID of the post being viewed?
  90. Update an existing post in a custom post type
  91. Check for custom field value in different post type than current one and do something
  92. Changing to different post type maintains the redirection?
  93. Post Meta for Custom Post Types
  94. getEntityRecords/useEntityRecords: How to use CPT metadata?
  95. I am having a problem with fetching product data in the Gutenberg block editor
  96. CPT meta values intermittently return empty
  97. Quering a post object based on another related post object
  98. rest_api_init is not getting invoked inside a Class
  99. Normal Posts and Custom Posts with Date Query
  100. Optimizing storage of Post Meta Entries
Categories custom-post-types Tags custom-post-types, notifications, post-meta
Custom query with custom filtering returning incorrect results
Block content rendered with inline CSS. How do I reuse it in a headless setup?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Post Navigation Elementor
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • WPFacet multiple loop displaying duplicate content
  • Get the name of the template/*html file used
  • Fix: WordPress.DB.PreparedSQL.NotPrepared Plugin Check (PCP)
  • Removing unnecessary CSS and JS code from wp_head()
  • hexagonal image gallery. Am I on the right track? [closed]
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress