Admin & Dashboard PHP Intermediate

Show the Pending Posts Count in the Admin Menu

Add a red bubble with the number of posts waiting for review next to Posts in the admin menu.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 18 lines
add_action( 'admin_menu', function (): void {
	global $menu;

	if ( ! current_user_can( 'edit_others_posts' ) ) {
		return;
	}
	$pending = (int) wp_count_posts( 'post' )->pending;
	if ( ! $pending ) {
		return;
	}

	foreach ( $menu as $i => $item ) {
		if ( 'edit.php' === ( $item[2] ?? '' ) ) {
			$menu[ $i ][0] .= sprintf( ' <span class="awaiting-mod count-%1$d"><span class="pending-count">%1$d</span></span>', $pending );
			break;
		}
	}
}, 99 );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

When contributors submit posts for review, editors have to remember to check. WordPress shows bubbles for pending comments and updates, but not for posts. This snippet adds one.

How it works

wp_count_posts() returns post counts by status, cached by WordPress. If there are pending posts, the snippet finds the Posts item in the global $menu array and adds a counter using the same awaiting-mod markup as the Comments bubble, so it looks native.

Only users who can edit other people’s posts, editors and administrators, see it.

Things to watch

  • To do the same for another post type, change 'post' and 'edit.php' to, for example, 'product' and 'edit.php?post_type=product'.

How to test it

Submit a post for review as a contributor, then log in as an editor. A “1” bubble should show next to Posts.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only