Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am sorry for this nooby question, but I just don't get it :

I was working with the function reference for wp_nav_menu and this is my line of code:

<?php wp_nav_menu( array('theme_location' => 'header-menu','items_wrap' => '%3$s') ); ?>

But the menu is displayed in <ul><li> anyway. (I want to remove that and make the menu horizontal). I can put anything in the items_wrap, it will always be the default <ul> The theme_location is maybe not working too, but since I have only one menu yet, it displays the right one.

I want to say sorry again if this is very stupid, which I guess it is, but I ask for your patience and help, just a beginner here.

Full index.php:

<?php get_header(); ?>
<?php if(isset($_GET['nav'])) {
$nav = $_GET['nav']; } ?>
<body>

<div id="topbar">
    <div id="orangebar"></div>
    <div id="top-middle">
        <a href="<?php echo home_url(); ?>"><img id="logo" src="<?php bloginfo('template_directory'); ?>/img/logo.png" /></a>
        <div id="menu">
<?php
remove_all_actions( 'wp_nav_menu_args' );
remove_all_actions( 'wp_nav_menu' );

echo "\n\n<!-- start menu -->\n";
wp_nav_menu( array( 'theme_location' => 'header-menu', 'items_wrap' => 'j' ) );
echo "\n<!-- end menu -->\n\n";
?>
        </div>
    </div>
</div>
<div id="center">
    <div id="centershade"><img id="shade" src="<?php bloginfo('template_directory'); ?>/img/shade.png" /></div>
    <div id="main">

        <a href="facebook link" target="_blank"><img id="fbbutton" src="    <?php bloginfo('template_directory'); ?>/img/buttons/fb.gif" /></a>
        <a href="twitter link" target="_blank"><img id="twitbutton" src="<?php bloginfo('template_directory'); ?>/img/buttons/twitter.gif" /></a>

        <div id="main-content">
            <?php if (!( isset($nav) ) ) { include('startpage.php');} else { include($nav+'.php');} ?>

        </div>
    </div>
</div>
<?php get_footer(); ?>

functions.php:

<?php add_action( 'init', 'register_my_menu' );

function register_my_menu() {
    register_nav_menu( 'header-menu', __( 'Header Menu' ) );
}

?>

Ok, please try to get over unstandardized naming and strange ways of achieving stuff, this is one-third learning, one-third testing and one-third development..

share|improve this question
2  
Unordered lists can be styled vertically or horizontally. –  Charles Clarkson Sep 22 '13 at 18:41
    
Well yes, but anyways this thing is still a problem. If the "theme_location" does not work, it will be a big problem when I add another menu. And "items_wrap" is more powerful than just removing ul... –  Argentus Sep 22 '13 at 18:48
1  
The code you are using above works on my web site. The <ul></ul> tags are removed. The list items are still wrapped in <li></li> tags. The documentation does not indicate that the items_wrap argument will remove the <li></li> tags. Your conclusion that the theme_location argument "maybe not working too" is only a guess until you actually test your conclusion. –  Charles Clarkson Sep 22 '13 at 18:59
    
On my server, the '<ul>' is not removed. I did not test with adding new menus, but I did try adding an '$after' string and of course, it did not work. Well this is a problem already. –  Argentus Sep 22 '13 at 19:02
1  
That is perplexing. Try adding more code near the menu PHP code you provided above. Something like echo '<!-- menu started -->'; before and echo '<!-- menu ended -->'; after, then check the browser page source to see if the <ul></ul> tags are inside those comments or outside them. –  Charles Clarkson Sep 22 '13 at 19:09
show 4 more comments

2 Answers

The items_wrap argument is in fact a sprintf-ed argument.

When you look into Core source:

'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>'

...you see that you have to use the arguments to let core do its work.

sprintf( $args->items_wrap, esc_attr( $wrap_id ), esc_attr( $wrap_class ), $items );

Here're the %-arguments:

  • %1$s -> $wrap_id
  • %2$s -> $wrap_class
  • %3$s -> $items

Now to replace the container, you'll need to use for e.g. something like the following:

'items_wrap' => '<div id="1%$s" class="%s$s">%3$s</div>'

Keep in mind that this is not the container. The container itself is only allowed to be a div or nav element. But you can extend the list of allowed container elements:

$allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) );
share|improve this answer
    
Yes, I know. When I set 'items_wrap' to ' ', it should not print the menu items at all. But it does, as if it did not even consider the argument. –  Argentus Sep 23 '13 at 10:20
    
IIRC you can't drop blank values in. Internally PHP should overwrite empty statements as wp_parse_args() basically is a prepare-wrapper for array_merge(). Maybe you can use &nbsp;, but I doubt that it will prove useful. Try replacing it with any char or string first. –  kaiser Sep 23 '13 at 10:38
    
That is a good point, but the results are still the same. ( I set items_wrap to 'j' ) –  Argentus Sep 23 '13 at 11:40
    
Please update your question with what you've tried, what the output/result was and where it's failing. Thing get slightly confused, spread and lost in the comments. –  kaiser Sep 23 '13 at 12:00
    
Yes, I will do that. –  Argentus Sep 23 '13 at 20:05
add comment

This is getting too long for comments. Try debugging with this in place of the code you originally posted in your question:

<?php
remove_all_actions( 'wp_nav_menu_args' );
remove_all_actions( 'wp_nav_menu' );

echo "\n\n<!-- start menu -->\n";
wp_nav_menu( array( 'theme_location' => 'primary', 'items_wrap' => '%3$s' ) );
echo "\n<!-- end menu -->\n\n";
?>

Check the browser page source for the <ul></ul> tags.

This should test to see if anything is overriding the menu arguments or menu output through PHP using a filter. The extra newlines (\n) I placed in the echo statements should make the menu easier to locate in the browser page source.


Well, still the same result: comment > div > ul > li ...

Weird. What is the full markup that appears starting with the <!-- start menu --> comment. With the items_wrap argument removed, on my server this follows:

<!-- start menu -->
<div class="menu-primary-container"><ul id="menu-primary-1" class="menu">

BTW, you can add code and markup to a comment by adding a backtick ` before and after it. On my keyboard, the backtick key is left of the numeral 1 key.

share|improve this answer
    
Well, still the same result: comment > div > ul > li –  Argentus Sep 22 '13 at 19:59
    
See the edit for more test code. –  Charles Clarkson Sep 22 '13 at 20:14
    
I just discovered that on a slovak keyboard layout, I can write it with Shift+Alt Gr+ 7 twice. <!-- start menu --> <div class="menu"><ul> <li class="page_item page-item-25"> link content </li> a few more list items </ul></div> <!-- end menu --> –  Argentus Sep 23 '13 at 10:12
    
Are you running a plugin or JavaScript code that automatically corrects invalid HTML? –  Charles Clarkson Sep 23 '13 at 11:28
    
I use no plugin at all, nor did I add any JS to my theme/design yet. –  Argentus Sep 23 '13 at 11:43
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.