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.
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; }
Thanks, was looking for this!
Agree, simple and easy! Great post!
Your code worked perfectly – thank you very much!
Nice tutorial. Works for me.
That worked great. Thank you! 🙂