Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // removes Menu-Items if they got no posts - tested with portfolio and posts
- // put it into child-theme functions.php
- function remove_empty_category_menu ( $items, $menu, $args ) {
- if ( ! is_admin() ) {
- global $wpdb;
- $nopost = $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, $nopost ) ) ) {
- unset( $items[$key] );
- }
- }
- }
- return $items;
- }
- add_filter( 'wp_get_nav_menu_items', 'remove_empty_category_menu',10, 3 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement