Change Primary Navigation for Front Page only

Community Forums Forums General Discussion Change Primary Navigation for Front Page only

This topic is: resolved

This topic contains 1 reply, has 1 voice, and was last updated by  scott9s 1 year, 3 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #40687

    scott9s
    Participant
    Post count: 4

    What I want to do is change the primary navigation for the front-page.php template only.  I want all my other pages to have a different primary navigation bar.

    I have tried  the following code to the front-page.php template:

    `add_filter( ‘wp_nav_menu_items’, ‘ss_custom_home_menu’, 10, 2 );`

    function ss_custom_home_menu($menu, $args) {
    	$args = (array)$args;
    	if ( 'primary' !== $args['theme_location']  )
    		return $menu;
    		return wp_nav_menu (array(
    				'menu' => 'MainHomeTop',
    				'container' => '',
    				'menu_class' => genesis_get_option('nav_superfish') ? 'nav superfish' : 'nav',
    				'echo' => 0
    			));
    }
    
    genesis();

    However, it doesn’t get all the proper formatting/classes, etc. Is there any easier way?

    Basically, on my home page, I want MenuHomeTop to be the primary menu, but on every other page, I want MenuTop to be the primary menu.

    #40689

    scott9s
    Participant
    Post count: 4

    Doh.  I just figured it out.  I was using the wrong filter.

    add_filter( 'wp_nav_menu_args' , 'ss_home_nav_menu' );
    
    function ss_home_nav_menu( $args ) {
    	if ( $args['theme_location'] == 'primary' ) { 
    		$args['menu'] = 'MainHomeTop'; 
    	}
    	return $args;
    }
    genesis();

     

    • This reply was modified 1 year, 3 months ago by  scott9s. Reason: added extra html tag. removed it
    • This reply was modified 1 year, 3 months ago by  scott9s. Reason: added extra html tag. removed it
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.