2011-03-30 72 views
13

我如何使用<?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的可溼性粉劑管理員/網頁的網頁:<?PHP get_header(); ?>

\t \t \t \t
    \t

    \t
  1. \t
\t
<?php get_footer(); ?> – Beto 2011-03-30 22:46:44

+0

是的,我通過外觀>菜單>添加它,並使用wp_nav_menu()函數來獲取我從那裏創建的菜單。 – Beto 2011-03-30 22:48:15

回答

8

這應該是你的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

1

以下爲我工作:

_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

-3

我用jquery來修復它。

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

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

0

如果你像我一樣希望從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 
)); 
-1

你讓事情太難了!相反,使用CSS display:none作爲自定義菜單的特定.home項目。它像一個魅力。例如:

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