WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Remove 'Home' From Menu (9 posts)

  1. Kristian Matthews
    Member
    Posted 3 years ago #

    I'm creating my own WordPress theme, I'm using the basis of the default theme, I've run into a problem…

    In the menu bar, the 'Home' item is fine on the homepage, but when it's on a different page, post, etc… then it doesn't seem I can customise it using the CSS.

    So can I remove, replace or add menu items?

    I'm using <?php wp_nav_menu(array('container_class'=>'menu-header','theme_location'=>'primary')); ?> to load the menu, but I'm not able to assign custom IDs or classes to the ul or li items.

    Normal State
    Broken State

    I thought maybe this page would be helpful, but can't work out how.

    http://codex.wordpress.org/Function_Reference/wp_nav_menu

  2. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    You can remove the "Home" link using a filter. Add this to your Theme's functions.php file:

    function mytheme_nav_menu_args( $args ) {
        $args['show_home'] = false;
        return $args;
    }
    add_filter( 'wp_nav_menu_args', 'mytheme_nav_menu_args' );

    And if you want to remove the "Home" link from the default fallback menu, add another filter:

    add_filter( 'wp_page_menu_args', 'mytheme_nav_menu_args' );
  3. Kristian Matthews
    Member
    Posted 3 years ago #

    Do I add it underneath the part that has similar code?

  4. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    Do I add it underneath the part that has similar code?

    Impossible to answer, without knowing what code is in your functions.php file.

    What is this "similar code"?

  5. Kristian Matthews
    Member
    Posted 3 years ago #

    functions.php

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

    And what code do I use in the other theme files?

  6. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    First, unless you're adding a function to the Twenty Ten functions.php file (and you shoudn't be doing that), then you need to name that function something different. Replace twentyten with the name of your current Theme (or even just twentyten_child if you're using a Twenty Ten Child Theme.

    Second, the Home link is showing up because that function is explicitly telling WordPress to output a Home link.

    Either remove the function entirely, or change this:

    $args['show_home'] = true;

    to this:

    $args['show_home'] = false;
  7. Kristian Matthews
    Member
    Posted 3 years ago #

    What do you mean 'I shouldn't be doing that', I've duplicated the Twenty Ten theme to use it as a basis for my own (Which wont be distributed), it's just because I'm very new to this.

    So is there no way I can keep the other code and just use the new one I add with a custom name?

  8. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    What do you mean 'I shouldn't be doing that', I've duplicated the Twenty Ten theme to use it as a basis for my own (Which wont be distributed), it's just because I'm very new to this.

    If you've forked Twenty Ten, then there's probably not an issue. The problem that we often run into is that people have issues with function name conflicts.

    So is there no way I can keep the other code and just use the new one I add with a custom name?

    I don't really understand this question?

  9. Kristian Matthews
    Member
    Posted 3 years ago #

    Nevermind, I've removed the old code and replaced it with your code. Worked like a charm. Thank you so much.

Topic Closed

This topic has been closed to new replies.