WordPress Add Home link to wp_nav_menu()
If you want add “Home” link to your wordpress wp_nav_menu() function then you have to add following code inside your themes function.php file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | add_filter( 'wp_nav_menu_items' , 'add_home_link' , 10, 2 ); function add_home_link( $items , $args ) { if (is_front_page()) $class = 'class="current_page_item"' ; else $class = '' ; $homeMenuItem = '<li ' . $class . '>' . $args ->before . '<a href="' . home_url( '/' ) . '" title="Home">' . $args ->link_before . 'Home' . $args ->link_after . '</a>' . $args ->after . '</li>' ; $items = $homeMenuItem . $items ; return $items ; } |