Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Add menu to Genesis child theme WordPress

  • SOLVED

I need to add a different primary menu on pages, posts, archives/etc in the Altitude Pro theme:

* Primary menu on homepage must stay as is.

* Different primary menu in the same position with same styling everywhere other than the homepage (pages, posts, archives, 404, etc)

Prefer to use functions.php to make this happen.

Absolutely do not want to use any type of bloated plugin.

Answers (5)

2018-02-04

timDesain Nanang answers:

open functions.php file under Altitude Pro theme folder,
replace line 100 - 108 with the following code:

// Add support for footer menu.
add_theme_support( 'genesis-menus', array(
'secondary' => __( 'Before Header Menu', 'altitude-pro' ),
'primary' => __( 'Header Menu', 'altitude-pro' ),
'archive' => __( 'Header Archive', 'altitude-pro' ),
'singular' => __( 'Header Singular', 'altitude-pro' ),
'footer' => __( 'Footer Menu', 'altitude-pro' ),
) );

// Unregister the header right widget area.
unregister_sidebar( 'header-right' );

// Reposition the primary navigation menu.
remove_action( 'genesis_after_header', 'genesis_do_nav' );
add_action( 'genesis_header', 'genesis_do_nav_alt', 12 );
function genesis_do_nav_alt() {

$class = 'menu genesis-nav-menu menu-primary';
if ( genesis_superfish_enabled() ) {
$class .= ' js-superfish';
}

if ( genesis_a11y( 'headings' ) ) {
printf( '<h2 class="screen-reader-text">%s</h2>', __( 'Main navigation', 'genesis' ) );
}

if(is_home() || is_front_page()){
$menu_id = 'primary';
}
elseif(is_archive()){
$menu_id = 'archive';
}
elseif(is_singular()){
$menu_id = 'singular';
}
else {
$menu_id = 'primary';
}

genesis_nav_menu( array(
'theme_location' => $menu_id,
'menu_class' => $class,
) );

}

add_filter( 'genesis_archive_nav', 'genesis_do_nav_output', 10, 3 );
add_filter( 'genesis_singular_nav', 'genesis_do_nav_output', 10, 3 );
add_filter( 'genesis_primary_nav', 'genesis_do_nav_output', 10, 3 );
add_filter( 'genesis_do_nav', 'genesis_do_nav_output', 10, 3 ); // Handle back-compat
function genesis_do_nav_output($nav_output, $nav, $args){
$nav_markup_open = genesis_structural_wrap( 'menu-primary' , 'open', 0 );
$nav_markup_close = genesis_structural_wrap( 'menu-primary' , 'close', 0 );

$nav_output = genesis_markup( array(
'open' => '<nav %s>',
'close' => '</nav>',
'context' => 'nav-primary',
'content' => $nav_markup_open . $nav . $nav_markup_close,
'echo' => false,
'params' => $params,
) );

return $nav_output;
}

2018-02-05

Arnav Joy answers:

are you still looking for help?
what's your site url ?


Arnav Joy comments:

can you please contact me at: [email protected]

2018-02-08

Mohamed Ahmed answers:

If you still need help you can contact us at meno010 @yahoo with your site URL also with any other requirements

2018-02-09

Reigel Gallarde answers:

Are you still in need of help?

2018-02-04

Bob answers:

I think this plugin will help you.
https://wordpress.org/plugins/menu-swapper/

https://codecanyon.net/item/different-menu-in-different-pages/7857908?ref=sahriq222


Bob comments:

you can add code in functions.php like that.

after registering menu location you can add menus to particular location from wordpress backend.

then second filter is based on condition which change location as required.

function register_my_menu() {
register_nav_menu('pages-menu',__( 'Pages Menu' ));
register_nav_menu('posts-menu',__( 'Posts Menu' ));
register_nav_menu('menu404',__( '404 Menu' ));
}
add_action( 'init', 'register_my_menu' );
function modify_nav_menu_args( $args )
{
if( 'top' == $args['theme_location'] )
{
if(is_page())
$args['theme_location'] = 'pages-menu';

if(is_single())
$args['theme_location'] = 'posts-menu';

if(is_404())
$args['theme_location'] = 'menu404';
}

return $args;
}

add_filter( 'wp_nav_menu_args', 'modify_nav_menu_args' );


Bob comments:

please note you have do some modification based on your theme.

in above example "top" is based on twentyseventeen theme