• Hi Guys

    I want to remove the “Home” menu item from custom menus that appear in a “custom menu” sidebar widget.

    I’ve found the code that appears to be adding it to all my menus, including the top menu area (I want “Home” kept there)

    // Add home link to menus
    	function new_nav_menu_items($items) {
    		$homelink = '<li class="home"><a href="' . home_url( '/' ) . '">' . __('Home') . '</a></li>';
    		$items = $homelink . $items;
    		return $items;
    	}
    	add_filter( 'wp_nav_menu_items', 'new_nav_menu_items' );
    	add_filter( 'wp_list_pages', 'new_nav_menu_items' );

    How would I change this code so that it will only add “Home” to the custom menu if it’s in the main-nav position (refer my menu register code below)

    // Register Custom Menu Function
    	function register_custom_nav() {
    		if (function_exists('register_nav_menus')) {
    			register_nav_menus( array(
    				'main-nav' => __( 'Main Navigation', 'themify' ),
    				'footer-nav' => __( 'Footer Navigation', 'themify' ),
    			) );
    		}
    	}

    Thanks for your help.

Viewing 1 replies (of 1 total)
  • Thread Starter Wasca

    (@wasca)

    Ok I figured this one out on my own, here is the resulting code, hope it helps someone else.

    // Add home link to menus
    	function new_nav_menu_items($items, $args) {
    		if( $args->theme_location == 'main-nav' ){ //Only if the the main-nav area (not sidebar menu widgets)
    			$homelink = '<li class="home"><a href="' . home_url( '/' ) . '">' . __('Home') . '</a></li>';
    			$items = $homelink . $items;
    		} else {
          return $items;
    		}
    			return $items;
    	}
    	add_filter( 'wp_nav_menu_items', 'new_nav_menu_items', 10, 2 );
    	add_filter( 'wp_list_pages', 'new_nav_menu_items' );
Viewing 1 replies (of 1 total)
  • The topic ‘Remove "Home" From Custom Menu’ is closed to new replies.