Support » Fixing WordPress » Nav Menu, Remove Container

  • Hello All,

    I am having a massive issue with a menu…

    I want to remove the div container from the nav menu created by:

    wp_nav_menu( array( 'theme_location' => 'primary', 'container' => '' ) );

    (based in header.php)

    and the menu is registered by:

    register_nav_menus( array(
        'primary' => __( 'Primary Menu', 'makin' ),
    ) );

    (based in functions.php)

    with the theme folder named makin and the theme named makin.

    Anyone got any ideas?
    __________________
    Laurence S Care

Viewing 15 replies - 16 through 30 (of 33 total)
  • @esmi Which theme are you doing that in and could you show me the registering function from the functions.php file please.

    and makin by the way is the name of the folder and theme, the menu is named using primary.

    I just checked my /themes/functions.php and I have

    register_nav_menu( 'primary', __( 'Primary Menu', 'twentyeleven' ) );

    so if you have

    register_nav_menu( 'primary', __( 'Primary Menu', 'makin' ) );

    ‘makin’ IS your default, you do not have an assigned menu:

    . . . . must have a menu assigned to it in administration!

    administration meaning dashboard.

    esmi

    (@esmi)

    Forum Moderator

    Which theme are you doing that in

    One of my own themes – literally.

    could you show me the registering function

    register_nav_menus( array(
    		'primary' => __( 'Primary Menu', 'collage' ),
    ) );
    esmi

    (@esmi)

    Forum Moderator

    ‘makin’ IS your default

    Uh? No – that’s the theme’s textdomain name. It has nothing to do with it.

    register_nav_menus( array(
    ‘primary’ => __( ‘Primary Menu’, ‘collage’ ),
    ) );

    So then I assume collage is the name of the themes folder or the name of the theme?

    If it is… do you have any other functions setting up that menu in the functions.php file?

    OK, I just checked, and for me, when I use wp_nav_menu( array( 'theme_location' => 'primary', 'container' => false ) ); on my page, it works just fine, until I go to dashboard and remove the custom-menu I assigned to Primary.
    Then, the container-div comes back.
    In dashboard the select-area is blank, when the default is active.
    What does it look like for you?

    esmi

    (@esmi)

    Forum Moderator

    I assume collage is the name of the themes folder or the name of the theme?

    It’s the name of theme. Or rather it’s the theme’s textdomain name and using it allows the theme to be translated easily. See /I18n_for_WordPress_Developers.

    do you have any other functions setting up that menu in the functions.php file?

    Nope.

    esmi

    (@esmi)

    Forum Moderator

    Oh – I have:

    // Get our wp_nav_menu() fallback, wp_page_menu(), to show a home link.
    function collage_page_menu_args( $args ) {
    	$args['show_home'] = true;
    	return $args;
    }
    add_filter( 'wp_page_menu_args', 'collage_page_menu_args' );

    but that won’t affect the enclosing markup for a custom menu. It only works when the default nav is being used (wp_page_menu) – in which case, a Home item is shown by default.

    I looked at an unmodified TwentyTen theme, and before you create a “menu” in “menus”, you can’t see the select-box I was talking about.
    If you can’t see the select-box, you are using the default menu, not an assigned one.
    It could be what is causing your problem, so I really think you should check.

    I am using the default menu but i believe the default menu is called Primary Menu so when registering a menu if i register Primary Menu i am registering the default page menu.

    @esmi This translation thing may be getting somewhere… If you do not know this then I will read a bit deeper. but to make that textdomain, is that done via any other function or is it just taken from the name of the theme.

    Why don’t you just take my suggestion and create a menu, you don’t even have to add links, just name it and assign it to Primary and see what happens.

    Because a duplicate menu would still need updating everytime you wish to add a page.

    That’s not something I would want to ask a third party to do.

    If I were making the site for myself then I would but I’d much rather not for someone else.

    esmi

    (@esmi)

    Forum Moderator

    to make that textdomain, is that done via any other function or is it just taken from the name of the theme

    In order for people to be able to use their own language files, you have add something to functions.php. I typically use something like:

    load_theme_textdomain( 'collage', get_template_directory() . '/languages' );
    $locale = get_locale();
    $locale_file = get_template_directory() . "/languages/$locale.php";
    if ( is_readable( $locale_file ) ) require_once( $locale_file );

    but that won’t affect the generated markup in any way. Listen to chreo. He(?) has a good point. If you have not set up a custom menu & assigned it to your Primary location yet, your theme/site will be using the default fallback – which is wp_page_menu(). That has its own, independent, parameters and generated output. wp_nav_menu’s parameters only kick in when your custom menu is being displayed.

    The bad news is that there isn’t a parameter in wp_page_menu to remove its enclosing <div></div>. The good news is that you don’t have to fallback to wp_page_menu. You could use (say) wp_list_pages() or something else entirely. You can specify exactly what function what you want to use via the fallback_cb parameter in wp_nav_menu().

    @esmi It’s she, but thank you!

    In TwentyEleven, there is the option that any new page be automatically listed in your menu. If it’s possible there, it’s possible in your theme, you just have to find out where they put the code for it.

Viewing 15 replies - 16 through 30 (of 33 total)
  • The topic ‘Nav Menu, Remove Container’ is closed to new replies.