hide category menus with zero articles
This commit is contained in:
@ -76,6 +76,19 @@ function ildi_register_sidebars() {
|
||||
);
|
||||
}
|
||||
|
||||
function ildi_nav_remove_empty_terms ( $items, $menu, $args ) {
|
||||
global $wpdb;
|
||||
$empty = $wpdb->get_col( "SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE count = 0" );
|
||||
foreach ( $items as $key => $item ) {
|
||||
if ( ( 'taxonomy' == $item->type ) && ( in_array( $item->object_id, $empty ) ) ) {
|
||||
unset( $items[$key] );
|
||||
}
|
||||
}
|
||||
return $items;
|
||||
}
|
||||
add_filter( 'wp_get_nav_menu_items', 'ildi_nav_remove_empty_terms', 10, 3 );
|
||||
|
||||
|
||||
// add_action('init', 'register_ildi_menu');
|
||||
add_action( 'after_setup_theme', 'register_ildi_menus', 0 );
|
||||
add_action( 'wp_enqueue_scripts', 'ildi_styles' );
|
||||
|
Reference in New Issue
Block a user