$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>plugin development - How to add notification in the sidebar of the administration panel when a Custom post type is created?|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

plugin development - How to add notification in the sidebar of the administration panel when a Custom post type is created?

matteradmin7PV0评论
This question already has answers here: How to add notification bubble for my custom admin menu page (2 answers) Closed 6 years ago.

I have added a custom post type called: "Partners", what I want is that when a new one is created, a notification appears in the sidebar of Wordpress.

For example:

regards!

This question already has answers here: How to add notification bubble for my custom admin menu page (2 answers) Closed 6 years ago.

I have added a custom post type called: "Partners", what I want is that when a new one is created, a notification appears in the sidebar of Wordpress.

For example:

regards!

Share Improve this question asked Feb 27, 2019 at 19:23 Maynor PeraltaMaynor Peralta 212 bronze badges 1
  • What have you tried so far? Where exactly are you stuck? – norman.lol Commented Feb 27, 2019 at 23:34
Add a comment  | 

1 Answer 1

Reset to default 2

It is shockingly simple: you have to dyamically set the admin page title, adding a specific markup:

<span class='awaiting-mod count-3'>
  <span class='pending-count'>3</span>
</span>

So for example if you want to show the number of custom posts you have to do something like this when declaring the options page:

$notif_count = wp_count_posts('my_post_type'); //insert your post type
add_menu_page("My Page Title", 
              "My Page Title <span class='awaiting-mod count-$notif_count'><span class='pending-count'>$notif_count</span></span>", 
              'administrator',
              'my_slug', 
              'my_handler_function'
);

Notice the php variable $notif_count inside the second parameter of add_menu_page.

Post a comment

comment list (0)

  1. No comments so far