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. what is the correct way to compare dates in a WP query_posts meta_query
  2. Get post with multiple meta keys and value
  3. Echo all meta keys of a custom-post TYPE
  4. How to Make an admin_notices Message That Disappears Once the User Leaves That Particular Page?
  5. Post metadata deletes itself
  6. How to create a mini directory in WordPress?
  7. Admin to user notices – best practices?
  8. Custom Post Type: Set post_title equal to a custom post type field
  9. I can’t set meta_key in my custom post type query
  10. Can’t sort order of wp_query with 2 meta keys
  11. How to get source of custom meta image?
  12. How can I include meta box content when searching?
  13. update a post meta from a single table cell TablePress
  14. Automatically adding meta data to posts or multiple query help
  15. Trigger “unsaved changes” dialog for custom post meta changes
  16. Conditionally Query Custom Post Types by Post Meta for Blog Home Page?
  17. Displaying custom posts only if custom meta box’s date is not expired
  18. Displaying Metabox value (custom post type taxonomy)
  19. How do I sort a custom post type admin column using two meta keys?
  20. How can I display my custom metaboxes on a custom post template?
  21. Custom Post Type, Saving Multiple Checkboxes
  22. Create a random unique 6 digit number as custom field for custom post type
  23. Export entries and multiple custom field meta to .csv?
  24. how to interconnect custom post types?
  25. orderby in custom WP Query does not work
  26. Insert post metadata for all posts in CPT at once if metadata no existent
  27. Display custom post type from dynamic custom field
  28. Populate dropdown from one custom post type inside another custom post type
  29. Notice: Undefined index: error and understanding wordpress
  30. Custom Post Types. Are there any disadvantages/advantages in using a plugin to develop them?
  31. Deleting Custom Posts & Meta Data on Uninstall
  32. Notify admin on new submit
  33. How do I create an archive page as a including metadata?
  34. A better way to add a meta box to custom post types
  35. Two Custom Post Types Many to Many Relationship
  36. how can I register a post_meta field in an existing CPT and then call it again with get_post_custom()?
  37. post meta parameter in post custom-post-type endpoint with restapi
  38. How do I set all of a particular post meta to a value within the custom post type I’m in?
  39. Update postmeta Parent when post_status child change
  40. Update database from Quick Edit according to Checkbox state of Custom Post Type
  41. Custom fields (wp_post_meta) vs Custom Table for large amount of data
  42. Dynamic Custom Fields
  43. Show Custom Post Type meta boxes only on Page Edit
  44. Send notification to the admin when new custom post is submitted
  45. Custom filter function not working with Custom post type
  46. List Taxonomies: Don’t list taxonomy if it has no post – depending on custom post-meta?
  47. Remove Post Custom Meta Box
  48. Meta Data for Custom Post Type not saving
  49. Using preg_replace to filter custom textarea
  50. Check if post with same meta value exists
  51. Do posts, pages and / or custom post type objects have unique ID numbers or can there be multiple objects with the same IDs?
  52. Archieve.php not loading for custom post type
  53. Meta data (Tags and Categories) for Custom Posts not showing.
  54. Display different information of a custom post type
  55. Create Array from custom post type to display a slider
  56. How to get specific post meta by title or id
  57. How can I display a drop-down select of Post Names
  58. $post->post_meta not pulling any post in wordpress/php
  59. WP_Query of custom post type sorted by meta_key has unexpected results
  60. copy images from custom field to another custom field
  61. Cannot obtain custom meta information
  62. Save Metabox Custom Field Value
  63. Meta box data not saving
  64. How can I get some of a posts meta data whilst it is still inserting?
  65. delete duplicate meta_value with same post_id
  66. Search CPT Title AND Meta
  67. Empty meta-box returns publishdate if no value is set?
  68. Building tags and archive using meta from custom post type
  69. Filter search posts by post meta?
  70. Custom Meta Box with variable number of fields
  71. How to create review point system for CPTs (many-to-many relationship)
  72. Using publish_{custom-post-type} hook for custom post type to update meta doesn’t work
  73. SELECT custom post type and its meta in SQL
  74. Unable to gather Image URL from Custom Post Type’s; Custom Meta Field
  75. Attaching more than 1 parent (Post) to a media file
  76. How to return/export only data showing on screen in custom post type view all screen
  77. Use WP_query to match post types based on custom field values
  78. Custom meta fields not showing up in WP_Response Object via custom endpoint
  79. How to get post by meta value
  80. Get meta values from parent post and save in child post
  81. How do I get all authors posts of a custom post type outside loop
  82. Stored meta from attachment, video length?
  83. Custom post type meta fields missing on save_post_type
  84. Order posts by meta value hiding posts instead of re-ordering
  85. custom search results – order results differently by post type
  86. How do I extract the contents of a CPT’s custom field for all posts?
  87. How to get post meta for custom post type and taxonomy
  88. how to display notifications in the wordpress menu when a new post is published
  89. get_post_meta for Custom Post Type ( CPT )
  90. Complex strcuture as CPT or taxonomy for use in woocommerce product variations [closed]
  91. How to create content automatically when a post is published?
  92. Add auto increment value to custom meta
  93. Return only custom post types for the page, not all
  94. Retrieve post data via WPDB class
  95. Create action running on trashed_post hook to modify post_meta value
  96. Random meta field from specific custom post type
  97. Custom Post Type meta value is being saved in array, instead of just the string (as value)
  98. Custom Form Data save after Login User
  99. Changing to different post type maintains the redirection?
  100. rest_api_init is not getting invoked inside a Class
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
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 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