如何从wp_nav_menu中删除“主页”链接!

如何从wp_nav_menu中删除“主页”链接!

问题描述:

我如何使用<?php wp_nav_menu(array('menu' => 'news', 'show_home' => false)); ?>如何从wp_nav_menu中删除“主页”链接!

我试图'show_home' => false'show_home=0'但既不工作时,从我的链接的顶部出现摆脱“家”链接。

+0

后从WP-头的代码,并指定allso如果 '家' 是加入通 – 2011-03-30 21:17:49

+0

从index.php的可湿性粉剂管理员/网页的网页:

\t \t \t \t
    \t

    \t
  1. \t
\t
Beto 2011-03-30 22:46:44
+0

是的,我通过外观>菜单>添加它,并使用wp_nav_menu()函数来获取我从那里创建的菜单。 – Beto 2011-03-30 22:48:15

这应该是你的functions.php

function page_menu_args($args) { 
    $args['show_home'] = FALSE; 
    return $args; 
} 
add_filter('wp_page_menu_args', 'page_menu_args'); 

编辑:不要忘了把它添加到您的地方菜单应该打印出来:

wp_nav_menu(array('echo'=>true)); 
+0

它会工作,如果我通过wp-admi /页面添加一个页面的'家'的页面?让我们在发布答案之前等待一些细节。 – 2011-03-30 21:22:18

+0

谢谢,我会尝试代码。 poelinca我不知道你的意思,在外表>菜单>我没有检查过家,如果这就是你的意思。 – Beto 2011-03-30 22:34:23

+0

这个工作适合你吗? – 2011-03-31 03:19:59

以下为我工作:

_nav_menu(array('container_id' => 'topmenu', 'depth' => 0, 'menu_class' => 'sf-menu', 'theme_location' => 'topmenu')); 

我添加

function page_menu_args($args) { 
    $args['show_home'] = FALSE; 
    return $args; 
} 
add_filter('wp_page_menu_args', 'page_menu_args'); 

functions.php文件中。

+0

你在哪里添加了第一行_nav_menu(...? – TechyTimo 2012-11-28 18:00:35

我用jquery来修复它。

$("div.menu > ul li:first-child").css("display","none"); 
+0

你在哪里添加了这行? – TechyTimo 2012-11-28 18:00:54

如果你像我一样希望从WordPress默认菜单(wp_page_menu)删除了“家”的链接和家庭是一个页面(不相关博客文章),这是解决这个问题的一种方法:

中的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; 
     } 
    }  
} 

中的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 
)); 

你让事情太难了!相反,使用CSS display:none作为自定义菜单的特定.home项目。它像一个魅力。例如:

menu-blogroll .home {display:none !important;}