15 stu.

Exclude empty terms from menus

Dynamically exclude empty terms from nav menus

Treba dodati u functions.php:

add_filter( 'wp_get_nav_menu_items', 'gowp_nav_remove_empty_terms', 10, 3 );
function gowp_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;
}

Odgovori

Vaša adresa e-pošte neće biti objavljena. Nužna polja su označena s *