Don't forget to back it all up first
I did this by the following steps:
First creating your Primary menu. Navigate to Appearance > Menus and create your primary menu for your site. Check the “Primary Navigation Menu” checkbox and save this menu.
Next create another menu for pages and posts only. Navigate to Appearance > Menus and create another menu for your pages.
and name it “Alternate Primary”
Step 3: Now add this simple code in functions.php file
function gecko_nav_menu_args( $args ){
if( ( 'primary' == $args['theme_location'] ) && is_singular (array('post', 'page' ) ) ) // You can also add any CPT in here as well
{
$args['menu'] = 'Alternate Primary'; // Add your menu name here. My case it is "Alternate Primary"
}
return $args;
}
add_filter( 'wp_nav_menu_args', 'gecko_nav_menu_args' );
Done
Now on your home page you will see your Primary Menu and other pages will show your Alternate Primary Menu.
Leave a Reply