WordPress Snippets at WPcustoms

Function to add a HOME link to your primary navigation

This function creates a custom link in your primary navigation. You can modify it and add more links or insert any other html to your menus


/**
 * Snippet Name: Function to add a HOME link to your primary navigation
 * Snippet URL: http://www.wpcustoms.net/snippets/add-home-link-primary-navigation/
 */
 function addHomeMenuLink($menuItems, $args)
{
// change "primary_menu" to your theme's menu name
        if('primary_menu' == $args->theme_location)
        {
                if ( is_front_page() )
                        $class = 'class="current-menu-item"';
                else
                        $class = '';
                $homeMenuItem = '
  • ' . $args->before . '' . $args->link_before . 'Home' . $args->link_after . '' . $args->after . '
  • '; $menuItems = $homeMenuItem . $menuItems; } return $menuItems; } add_filter( 'wp_nav_menu_items', 'addHomeMenuLink', 10, 2 );