wrong wp_nav_menu displayed - wordpress

my url looks like this:
http://domain.com/?s=searchquery&post_type=qa_faqs
that page lists search results for "searchquery".
i then get the post type with
$post_type = $_GET['post_type'];
it echoes correctly
echo $post_type;
// Provides: qa_faqs
i then do an if/else to display a different menu via wp_nav_menu when $post_type is qa_faqs.
if ( $post_type == 'qa_faqs' ) {
echo 'we got qa_faqs over here';
wp_nav_menu(array('menu' => 'meta_menu', 'items_wrap' => '<dl id="%1$s" class="nice tabs vertical %2$s">%3$s</dl>', 'walker' => new sidenav_walker ));
} else {
echo 'no qa_faqs in da house';
wp_nav_menu(array('menu' => 'service_menu', 'items_wrap' => '<dl id="%1$s" class="nice tabs vertical %2$s">%3$s</dl>', 'walker' => new sidenav_walker ));
}
now to the funny part:
even though the page echoes 'we got qa_faqs over here', it displays the service_menu.
why´s that?

Found it - http://codex.wordpress.org/Navigation_Menus
Same problem was driving me nuts aswell.
Use 'theme_location' instead of 'menu' to point to which menu you want to output.

Try targetting the specific menu with something like:
<?php wp_nav_menu( array('menu' => 'Your Menu Name' )); ?>

I think you dont have any items on the meta_menu. Please create menu under Appearance section and assign it. :)

Related

How to display custom links in WordPress with wp_nav_menu?

I'm creating an one-page custom theme. I'm struggling with a custom menu, because I want to display custom links.
I've registered menu in functions.php file
function register_my_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' ),
)
);
}
add_action( 'init', 'register_my_menus' );
Then, I've displayed in header.php file like this:
<?php wp_nav_menu( array(
'theme_location' => 'top-menu',
'container' => 'ul',
'menu_class'=> 'd-flex main-menu'
) );
?>
I've added custom classes for ul tag, and that is okay. Navigation works but just for pages. When I create a page, a link for that page shows up in navigation. However, after creating custom links they don't appear in navigation.
I'm searching the Stachoverflow for some quiet time, but without success. How to resolve a described issue? Do you have an idea?
Thank you for your time.
You have register header menu with header-menu key and trying to get it by key of top-menu which is not possible. You have to use the header-menu key to add and get a header menu. we have updated the code. you can use this code.
<?php
wp_nav_menu( array(
'theme_location' => 'header-menu',
'container' => 'ul',
'menu_class'=> 'd-flex main-menu'
) );
?>

wp_nav_menu not working on category pages on wordpress

I created a couple of custom menus on wordpress using the appearance menu.
I want to display the right menu according to the page that I'm viewing. I wrote the script below in the header.php file in the seems to be working fine. It's pulling the correct menu according to the page that I'm visiting with the exception of the category pages.
When I'm on a category page, the wp_nav_menu function falls back to the fallback function, indicating that the menu doesn't exist?!
I was looking around and the solution that kept coming up was adding the following code but it doesnt seem to work.
<?php
wp_nav_menu('container_class=menu-header&theme_location=primary');
?>
Here is the full code that I added to the header.php file:
<?php
switch( $master_page ) {
case 'about':
wp_nav_menu(array(
'menu' => 'about',
'fallback_cb' => 'get_cat',
));
break;
case 'offer':
wp_nav_menu(array(
'menu' => 'offer',
'fallback_cb' => 'get_cat',
));
break;
}
?>
I'm really frustrated at this point. Any ideas?
I don't see where you are assigning a value to $master_page, so at this point it is just an empty variable.
You need to look into the is_page() and is_category() functions in WordPress and use if statements rather than a switch.
<?php
if( is_page( 'about' ) ) {
wp_nav_menu(array(
'menu' => 'about',
'fallback_cb' => 'get_cat',
));
} else {
...
}
?>

Insert another menu into WordPress... not working at all?

I am following this guide to "Add additional support for menus in your theme":
http://codex.wordpress.org/Navigation_Menus
I followed all of the steps, but this is the result:
http://puu.sh/30bMt.png
So, it's "inserting a menu" where I told it to.... however the items on the menu do not match up with what I have in the WordPress back-end, seen here...
http://puu.sh/30bQd.png
I only inserted 4 items into the menu "Test"... but it's displaying every page, instead of the 4 items I want.
I've attempted to do research to figure out what's going on to no avail; does anybody have any insight as to why this is acting funky?
Code where I'm "registering" the additional menu support... (themes function.php):
function register_my_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' )
)
);
}
add_action( 'init', 'register_my_menus' );
Code where I'm inserting the "Header Menu" itself... (themes header.php):
<?php
wp_nav_menu( array( 'theme_location' => 'extra-menu', 'container_class' =>'my_extra_menu_class' ) );
?>
If you are trying to call 'Header Menu' then the code in your header.php should look like this:
<?php wp_nav_menu(array('theme_location' => 'header-menu', 'menu_class' => 'my_extra_menu_class')); ?>
I'm not sure where you got 'extra-menu' from but WordPress doesn't know what that is since you didn't declare that in your register_my_menus function.
I hope that helps.
Here's an example of how I've implemented multiple menus in my WordPress install:
// Register Extra Menus
function new_register_menus() {
register_nav_menus(array('Products'=>'Products Nav', 'Support'=>'Support Nav', 'Company'=>'Company Nav' , 'Footer'=>'Footer Nav'));
}
add_action( 'init' , 'new_register_menus' );
//Code in my footer.php
<?php wp_nav_menu(array('theme_location' => 'Footer', 'menu_class' => 'nav')); ?>

working with wp_nav_menu on wordpress

I'm having an issue working with wp_nav_menu, I'm trying to create my own Theme for WP, now i've putted that code into my functions.php file,
function register_my_menu() {
register_nav_menu('header-menu',__( 'Header Menu' ));
}
add_action( 'init', 'register_my_menu' );
as the guide said, and now when I'm trying to combine it into my design, the paramters I pass in the wp_nav_menu function doesn't really do anything, and I dont really understand why, I tried to play with it but it doesnt seem like something gets changed.
`
wp_nav_menu( array( 'items_wrap' => '<ul id="danny" class="danny">%3$s</ul>','theme_location' => 'header-menu' ) );
`
it doesnt metter what I do, what I add as a paramter the output stays as it is, anyone has anyidea? am I missing something?
thanks!
Why not instead of registering your menu, you just use 'menu' parameter like this:
wp_nav_menu( array( 'items_wrap' => '<ul class="%2$s danny" id="danny">%3$s</ul>','menu' => 'header-menu' ) );
Take another peek at the Codex: http://codex.wordpress.org/Function_Reference/wp_nav_menu
Instead of passing that markup try the parameters for menu_class and menu_id. for example:
<?php wp_nav_menu( array( 'theme_location' => 'header-menu', 'menu_class' => 'danny', 'menu_id' => 'danny' ) ); ?>

user-menu in secondary-menu: why?

I've created a sub of the zen-theme. And am mighty proud of it, but up in the top right corner (#secondary-menu) the user-menu shows up - perfectly.
I just don't understand how it get's there?
In structure/blocks the user-menu appears in the Disabled section (Region: None)
In fact, there IS no region called "secondary-menu" (id of the element gotten from Firebug)
Isn't that strange?
I can't comment on your specific template files but the standard Zen page.tpl.php file has this in it:
<?php if ($secondary_menu): ?>
<nav id="secondary-menu" role="navigation">
<?php print theme('links__system_secondary_menu', array(
'links' => $secondary_menu,
'attributes' => array(
'class' => array('links', 'inline', 'clearfix'),
),
'heading' => array(
'text' => $secondary_menu_heading,
'level' => 'h2',
'class' => array('element-invisible'),
),
)); ?>
</nav>
<?php endif; ?>
Which should answer how the menu gets printed to the page. If you want to dig one step deeper, the $secondary_menu variable is set up in template_preprocess_page().
As to why it's the user menu...if you go to admin/structure/menu/settings you should see this:
If you change the secondary link source to something else you should see that reflected in your theme too.

Resources