Support » Fixing WordPress » Remove subpages from top menu

  • How do I prevent subpages from being listed in the top navigation bar?
    I’m planning on having pretty many subpages, in three categories – ‘Me’, ‘WWW’, and ‘Site’. And I just want those three, plus ‘Home’ to be in the top menu.

Viewing 15 replies - 1 through 15 (of 19 total)
  • If this “top navigation bar” is using wp_list_pages() to display Page links, see the Codex page on it for information on the ‘depth’ parameter:

    Setting ‘depth’ to 1 will force wp_list_pages() to display only the top (non-child) Pages.

    Hmm. I can’t find it.
    This is how my header.php looks:

    <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “”>
    <?php require_once get_template_directory().”/BX_functions.php”; ?>
    <html xmlns=”” xml:lang=”en” lang=”en”>
    <meta http-equiv=”Content-Type” content=”<?php bloginfo(‘charset’); ?>” />
    <title><?php bloginfo(‘name’); wp_title(); ?></title>
    <meta name=”generator” content=”WordPress <?php bloginfo(‘version’); ?>” />
    <link rel=”stylesheet” href=”<?php bloginfo(‘stylesheet_url’); ?>” type=”text/css” media=”screen, projection” />
    <link rel=”alternate” type=”application/rss+xml” title=”RSS 2.0″ href=”<?php bloginfo(‘rss2_url’); ?>” />
    <link rel=”alternate” type=”application/atom+xml” title=”Atom 0.3″ href=”<?php bloginfo(‘atom_url’); ?>” />
    <link rel=”pingback” href=”<?php bloginfo(‘pingback_url’); ?>” />
    <?php /*comments_popup_script(520, 550);*/ ?>
    <?php wp_head();?>

    <div id=”container”<?php if (is_page() && !is_page(“archives”)) echo ” class=\”singlecol\””; ?>>

    <!– header …………………………… –>
    <div id=”header”>
    <h1>“><?php bloginfo(‘name’); ?></h1>
    </div> <!– /header –>

    <!– navigation …………………………… –>
    <div id=”navigation”>

    <form action=”<?php echo $_SERVER[‘PHP_SELF’]; ?>” method=”get”>
    <input value=”<?php echo wp_specialchars($s, 1); ?>” name=”s” id=”s” />
    <input type=”submit” value=”Go!” id=”searchbutton” name=”searchbutton” />

      <li<?php if (is_home()) echo ” class=’selected'”; ?>>“>Home
      $pages = BX_get_pages();
      if ($pages) {
      foreach ($pages as $page) {
      $page_id = $page->ID;
      $page_title = $page->post_title;
      $page_name = $page->post_name;
      if ($page_name == “archives”) {
      (is_page($page_id) || is_archive() || is_search() || is_single())?$selected = ‘ class=”selected”‘:$selected=”;
      echo “<li”.$selected.”>Archives\n”;
      elseif($page_name == “about”) {
      (is_page($page_id))?$selected = ‘ class=”selected”‘:$selected=”;
      echo “<li”.$selected.”>About\n”;
      elseif ($page_name == “contact”) {
      (is_page($page_id))?$selected = ‘ class=”selected”‘:$selected=”;
      echo “<li”.$selected.”>Contact\n”;
      elseif ($page_name == “about_short”) {/*ignore*/}
      else {
      (is_page($page_id))?$selected = ‘ class=”selected”‘:$selected=”;
      echo “<li”.$selected.”>$page_title\n”;

    </div><!– /navigation –>

    <hr class=”low” />

    It is always good to mention in your initial post the theme you are using. From the code you posted I can tell you are using the Blix, which is a nice theme but a nightmare to modify – especially for new users. Maybe the author can give you some help.

    Ah yes, the Blix theme… you’ll have to do a little editing of the code above to get what you’re after.

    In the PHP block above (it starts with $pages = BX_get_pages();) right after the foreach line:

    foreach ($pages as $page) {

    add this:

    if(empty($page->post_parent)) {

    Then at the end (before the closing ?> tag for the block of code), insert another closing curly bracket:


    I tried it, but it didn’t work. It messed everything up –

    If Blix is going to be this hard to configure, I might as well just use another theme.

    <b>Edit:</b> I’m now using the default theme, and I’ve added the depth parameter and everything works fine.
    Thanks for your help. 🙂


    i read the artikel with joy, because i have the same problem. But I can´t change the thema because i´ve work to long to make it perfekt for me.
    Its the site:

    The Menupoint “Impressum” should be invisible.

    Did anyone know who I could get it away?

    @seifenspender: how about adding parametre exclude=6 to the wp_list_pages template tag (I assume that’s the correct page ID). That doesn’t change anything too drastically, it only removes the specified page link from the list. See the Codex for info how to use the parametre. (It’s just a comma-separated list of page IDs you want to exclude.)

    thank you . ok I want to try it.
    You mean the lines in the header.php, didn´t you?
    I not sure if I know what you mean. Where should I insert “exclude=6”?

    Here the code:
    $pages = BX_get_pages();
    if ($pages) {
    foreach ($pages as $page) {
    $page_id = $page->ID;
    $page_title = $page->post_title;
    $page_name = $page->post_name;
    if ($page_name == “archives”)

    and so on…

    could anybody help me?

    Ahh… special functions. That’s the correct place. You could add
    elseif ( $page_id==6 ) { /* ignore */ }
    after the similar looking “about_short” line (if you still have it). Before the else, anyway. Hmm, I’m not sure if the 6 should be in single quotes '6'. Try either way 🙂

    YEAH !!!
    Make me a baby.. Thanks a lot!!

    Ehm Sorry: It Works!!!!

    YEAH!!! Thank you

    I love the Blix theme, however I’m having the same problem.

    I think one of our many talented WordPress CSS/PHP gurus (not me), should make an update to the Blix files so that the subpages render as a smooth and simple CSS drop down from the main navigation.



    That would be something to discuss with the theme’s author….

    I did, I sent him an email.

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Remove subpages from top menu’ is closed to new replies.