WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Custom Menu - is_active_menu() (3 posts)

  1. ooeygui
    Member
    Posted 3 years ago #

    Is there a way to figure out whether or not a custom menu has items in it, and if not then echo nothing?

    I've tried everything I can think of and all I get is blank container <div> and <ul> items.

    The walker argument of the wp_nav_menu() function will specify the output of each menu item but not the container.

  2. ooeygui
    Member
    Posted 3 years ago #

    Ok so... has_nav_menu() will return true or false based on whether or not a "theme-location" for a menu actually has a menu assigned to it. That gets me partially there, I would like to then find out, if it DOES have a menu associated with it does that menu have items in it?

  3. ooeygui
    Member
    Posted 3 years ago #

    Got it! :)

    function is_active_nav_menu($location){
    
    	if(has_nav_menu($location)){
    
    		$locations = get_nav_menu_locations();
    		$menu = wp_get_nav_menu_items($locations[$location]);
    
    		if(!empty($menu)){
    			return true;
    		}
    
    	}
    
    	return false;
    
    }

Topic Closed

This topic has been closed to new replies.

About this Topic