Second Menu on Home

Viewing 4 posts - 1 through 4 (of 4 total)
  • #21220
    mKegan
    Participant

    Is it possible with this theme to create a Second Menu and place it on Top of the main one?

    I need to differentiate some links for example, for support.

    I found some tutorials and they said to add these lines on the funtions.php but it doesn’t work.

    add_action( ‘init’, ‘my_custom_menus’ );
    function my_custom_menus() {
    register_nav_menus(
    array(
    ‘primary-menu’ => __( ‘Primary Menu’ ),
    ‘secondary-menu’ => __( ‘Secondary Menu’ )
    )
    );
    }

    #21234
    bo-oz
    Participant

    Adding these lines just tells WordPress that the theme contains a primary and a secondary menu. You still need to include the menu in the HTML template. Today I made something similar, I’ll share it with you:

    
    add_action( 'init', 'register_user_menu' );
    function register_user_menu() {
            // just registering the menu
    	register_nav_menu('user-menu',__( 'User Menu' ));
    }
    
    // I'm injecting the menu in the 'enlightenment_before_header', you can also use a different hook for a different position inside the code, just take a look at header.php
    add_filter('enlightenment_before_header','enlightenment_before_header_bo');
    function enlightenment_before_header_bo() {
    	if ( is_user_logged_in() ) {
    	  // deleted this code, because it is website specific.
    	} else {
    // this actually creates a div and echo's the custom menu inside the theme
    		echo '<div class="top-user-menu">'.wp_nav_menu( array( 'theme_location' => 'user-menu', 'echo' => false ) ).'</div>';
    	}
    }
    
    • This reply was modified 9 years, 7 months ago by bo-oz.
    • This reply was modified 9 years, 7 months ago by bo-oz.
    #21237
    mKegan
    Participant

    bo-oz Thanks.

    Just one question (sorry if It sounds dumb): should I use just the code you gave me, or booth?

    Do I use it all on the “enlightenment_before_header” page?

    Once again, Thanks!

    #21240
    bo-oz
    Participant

    Hi,

    In the first part of the code I register the menu… you can customize this with your own code to include multiple menus.

    The enlightenment_before_header is just one place you can inject your own code… but the enlightenment template contains many of those places… so it basically depends where you would want the menu to show. Like I said, have a look at header.php to see which placeholders are there (or any other template file for that matter, footer.php if you would like to inject code in the lower part of the website).

Viewing 4 posts - 1 through 4 (of 4 total)

Tagged: ,

You must be logged in to reply to this topic.