Tektriks

Coding starts here
Home / Blog

How to add home & logout link in wp_nav_menu in WordPress


function addHomeMenuLink($menuItems, $args)
{
  if('main' == $args->theme_location)
  {
    if ( is_front_page() )
      $class = 'class="current-menu-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>';
  $loginoutlink = wp_loginout( home_url(), false );
                $menuItems = $homeMenuItem . $menuItems . $loginoutlink;
        }
        return $menuItems;
}
add_filter( 'wp_nav_menu_items', 'addHomeMenuLink', 10, 2 );

Leave a Reply

Be the First to Comment!

avatar
  Subscribe  
Notify of
tektriks logo