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;
}

Leave a Reply

Your email address will not be published. Required fields are marked *

6 Comments

  1. Sylvain Bousquet says:

    Thanks, was looking for this!

  2. Your code worked perfectly – thank you very much!

  3. Nice tutorial. Works for me.

  4. That worked great. Thank you! 🙂