• 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.

    https://codex.www.ads-software.com/Function_Reference/wp_nav_menu

Viewing 8 replies - 1 through 8 (of 8 total)
  • 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' );

    Thread Starter Kristian Matthews

    (@epickris)

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

    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”?

    Thread Starter Kristian Matthews

    (@epickris)

    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?

    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;

    Thread Starter Kristian Matthews

    (@epickris)

    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?

    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?

    Thread Starter Kristian Matthews

    (@epickris)

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

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Remove 'Home' From Menu’ is closed to new replies.