Last active
October 26, 2019 15:59
-
-
Save derpixler/6d73b30fee3dcaf6d119 to your computer and use it in GitHub Desktop.
Add WordPress Nav-Menu Counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Add Postcount to Adminmenu | |
Plugin URI: https://gist.github.com/derpixler/6d73b30fee3dcaf6d119 | |
Description: This Plugin adds a count bubble on Post menu | |
Version: 1.0 | |
Author: René Reimann | |
Author URI: http://www.rene-reimann.de | |
License: | |
Copyright 2015 René Reimann) ([email protected]) | |
This program is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License, version 2, as | |
published by the Free Software Foundation. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
*/ | |
/** | |
* add navmenu count bubble | |
* | |
* @author rreimann | |
* @return void | |
*/ | |
function add_menu_count(){ | |
global $menu; | |
foreach( $menu as $i => $menus ){ | |
if( $menus[2] == 'edit.php' ){ | |
$counted_posts = wp_count_posts( 'post' ); | |
$drafts = $counted_posts->draft; | |
$publish = $counted_posts->publish; | |
$future = $counted_posts->future; | |
$counted_posts = $drafts + $publish + $future; | |
$menu[$i][0] = $menus[0] . ' <span class="update-plugins count-'. $counted_posts .'"><span class="plugin-count">'. $counted_posts .'</span></span>'; | |
} | |
} | |
} | |
add_filter( 'custom_menu_order', 'add_menu_count' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Add Post Draft Count to Adminmenu | |
Plugin URI: https://gist.github.com/derpixler/6d73b30fee3dcaf6d119 | |
Description: This Plugin adds a draft count bubble on Post menu | |
Version: 1.0 | |
Author: René Reimann | |
Author URI: http://www.rene-reimann.de | |
License: | |
Copyright 2015 René Reimann) ([email protected]) | |
This program is free software; you can redistribute it and/or modify | |
it under the terms of the GNU General Public License, version 2, as | |
published by the Free Software Foundation. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
*/ | |
/** | |
* add navmenu count bubble | |
* | |
* @author rreimann | |
* @return void | |
*/ | |
function add_menu_count(){ | |
global $menu; | |
foreach( $menu as $i => $menus ){ | |
if( $menus[2] == 'edit.php' ){ | |
$counted_posts = wp_count_posts( 'post' ); | |
$counted_posts = $counted_posts->draft; | |
$menu[$i][0] = $menus[0] . ' <span class="update-plugins count-'. $counted_posts .'"><span class="plugin-count">'. $counted_posts .'</span></span>'; | |
} | |
} | |
} | |
add_filter( 'custom_menu_order', 'add_menu_count' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment