Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Is there a bug in navigation code of Flexibility3? WordPress

  • SOLVED

[[LINK href="http://www.flexibilitytheme.com/"]]Flexibility3[[/LINK]] offers an option to add a "home" link to the navigation. This does not work for me. For now, I've hard coded the link into the template, but I dislike going this route. Does anyone know if this is a known bug?

Answers (2)

2011-03-21

AdamGold answers:

Don't know if it's a known bug, but if you are using wp_nav_menu and want to automatically add the home link to your menu, add this code to your functions.php:

function addHomeMenuLink($menuItems, $args)
{
if('main' == $args->theme_location)
{
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>';

$menuItems = $homeMenuItem . $menuItems;
}

return $menuItems;
}

add_filter( 'wp_nav_menu_items', 'addHomeMenuLink', 10, 2 );


AdamGold comments:

Or even a better code:

// Filter wp_nav_menu() to add additional links and other output
function new_nav_menu_items($items) {
$homelink = '<li class="home"><a href="' . home_url( '/' ) . '">' . __('Home') . '</a></li>';
$items = $homelink . $items;
return $items;
}
add_filter( 'wp_nav_menu_items', 'new_nav_menu_items' );



If you are not using wp_nav_menu, let me know what function you are using and I will try to add the home link.

2011-03-22

Lucas Wynne answers:

Hey Lawrence, I'm working on a theme store. This is BY FAR the best code:

//////////////////////////////////////// Home page menu link option
function home_page_menu_args( $args ) {
$args['show_home'] = true;
return $args;
}
add_filter( 'wp_page_menu_args', 'home_page_menu_args' );