How do I get rid of the 'Home' link from appearing at the top of my links whe开发者_如何学Cn using <?php wp_nav_menu( array('menu' => 'news', 'show_home' => false)); ?>
I tried 'show_home' => false
and 'show_home=0'
but neither worked.
This should be in your functions.php
function page_menu_args( $args ) {
$args['show_home'] = FALSE;
return $args;
}
add_filter( 'wp_page_menu_args', 'page_menu_args' );
EDIT: Dont forget to add this to wherever your menu is supposed to print out:
wp_nav_menu( array('echo'=>true));
The following worked for me:
_nav_menu( array( 'container_id' => 'topmenu', 'depth' => 0, 'menu_class' => 'sf-menu', 'theme_location' => 'topmenu' ) );
And I add
function page_menu_args( $args ) {
$args['show_home'] = FALSE;
return $args;
}
add_filter( 'wp_page_menu_args', 'page_menu_args' );
In the functions.php
file.
If you are like me looking to remove the 'home' link from the default wordpress menu (wp_page_menu) and the home is a page (not blogposts), this is one way to solve it:
in functions.php:
function getPageBySlugname($slugname) {
$args = array(
'post_type' => 'page',
'hierarchical' => 0,
'post_status' => 'publish'
);
$pages = get_pages($args);
foreach ($pages as $page) {
if ($page->post_name == $slugname) {
return $page->ID;
}
}
}
in header.php
wp_page_menu(array(
'container' => 'div',
'show_home' => false, // Not sure what this is hiding, maybe if you have blogposts as home??
'echo' => true,
'exclude' => getPageBySlugname('homepage-slugname'), // change this to your slugname
));
You're making it way too hard! Instead, use CSS display: none for that particular .home item of a custom menu. It works like a charm. Example:
menu-blogroll .home {display:none !important;}
I used jquery to fix the same.
$("div.menu > ul li:first-child").css("display","none");
精彩评论