Change 'Home' link in menu wordpress 3 – function wp_nav_menu()

To change Home link in WordPress menu you can use the simple filter (in this example we use defaut theme „twentyten”):

1. Turn off echoing in function wp_nav_menu.
To do this open file functions.php ,which is located in your theme folder. Find proper line with wp_nav_menu function parameters and add new argument echo => false;

In my installation it looks like this:

function twentyten_page_menu_args( $args ) {
$args[’show_home'] = true;
$args[’echo'] = false;
return $args;
}

2. In file header.php, where wp_nav_menu function is called we do string replacement using str_replace function. In my case it looks like this:

$menu = wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); // fetch menu to variable
$menu = str_replace(„Home”, „About”, $menu); // replace Home string to About
echo $menu; // echo modified menu
?>


Leave a Comment

Question: