Isn’t it supposed to be like this instead?
wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary', 'before' => '<div class="x-left"></div>', 'after' => '<div class="x-right"></div>' ) );
Thread Starter
vuvex
(@vuvex)
Actually yes, that’s how it is, it’s just not doing anything. I can add whatever I want, it’s just not showing, it’s like the function is not called, or the ‘before’ and ‘after’ arguments are not appended to the final result.
The only thing I got working was a function from a website:
// Add ID and CLASS attributes to the first <ul> occurence in wp_page_menu
function add_menuclass($ulclass) {
return preg_replace('/<ul>/', '<ul id="nav" class="something-classy">', $ulclass, 1);
}
add_filter('wp_page_menu','add_menuclass');
…that I added into the functions.php file. It works on ul, but not li.
I tried to replace the ul with li, but there must be something that I am not doing right.
I just copy and pasted your wp_nav_menu code on my theme and it works.
HTML output:
<li class="menu-item menu-item-type-post_type menu-item-object-page current-menu-item page_item page-item-2 current_page_item menu-item-17">
<div class="x-left"></div>
<a href="http://site.com">Home</a>
<div class="x-right"></div>
</li>
Take not that they are inside the li tags.
Thread Starter
vuvex
(@vuvex)
That’s perfect! Thank you! At least I know it works for somebody.
I can’t get it to do anything. I should probably revert to the default theme and also try it there.
Thread Starter
vuvex
(@vuvex)
I am using version 3.1. Are you using something newer?
It should work starting from version 3.0.
Are you sure it’s the one being called in your theme? You can try to comment out the function call first and see if it still shows in your website.
Because it looks like your theme is using wp_page_menu instead, hence the filter you added in functions.php is working.
Thread Starter
vuvex
(@vuvex)
Hmmm… let me check that. I also enabled the original twenty_ten with the proper wp_nav_menu changes, and still nothing. Let me dig a bit deeper.
Thread Starter
vuvex
(@vuvex)
I bow to you! Thanks for your help, mate.
I followed your lead, and finally go to the comment right before the wp_nav_menu line, a pretty important comment:
<?php /* Our navigation menu. If one isn’t filled out, wp_nav_menu falls back to wp_page_menu. The menu assiged to the primary position is the one used. If none is assigned, the menu with the lowest ID is used. */ ?>
I ignored this line before since it was inside another php code section, I thought it had nothing to do witn the nav_menu. That was wrong.
Anyways, I created a custom menu and everything is fine now.
It’s always good to have a fresh look at things.
Thanks!
Did you create a menu in the admin? Appearance->Menus. This could possibly be the problem. You have to create one or else the function will call wp_page_menu instead.
Haha great! Great work solving it!