0

I'm looking for help on how to add specific menu on a specific page or pages with no plugin.

I know how to add and register a new menu like this:

//* Register third navigation menu position
function register_additional_menu() {
  register_nav_menu( 'third-menu' ,__( 'Third Navigation Menu' ));
}
add_action( 'init', 'register_additional_menu' );
add_action( 'genesis_before_content', 'add_third_nav_genesis' );

function add_third_nav_genesis() {
    echo'<div class="osastot-valikko">';
    wp_nav_menu( array( 'theme_location' => 'third-menu', 'container_class' => 'genesis-nav-menu js-superfish sf-js-enabled sf-arrows' ) );
    echo'</div>';
}

I would like to have a navigation menu named "Extra Menu" displayed only on three pages (post=6, post=7, post=8). What should I write in my function.php

Thanks!

1

Pages can have a specific template, so just create a new template and add the Menu on it.

You can copy the code on pages.php(this is the default page template) of you theme and paste on a new file (like "template-page-with-menu.php"). On the top of the code you must add the Template Name:

<?php /* Template Name: Page with Menu */ ?>

Then select this template on the pages that you want it.

enter image description here

  • Excellent suggestion. This way I could personalize those pages even more with specific sidebar contents etc. – Konstantin Nikkari Jan 22 '17 at 9:52
0

try working with a conditional statement:

function add_third_nav_genesis() {
    if( is_page( array( 6, 7, 8 ) ) ) {
        echo'<div class="osastot-valikko">';
        wp_nav_menu( array( 'theme_location' => 'third-menu', 'container_class' => 'genesis-nav-menu js-superfish sf-js-enabled sf-arrows' ) );
        echo'</div>';
    }
}

https://developer.wordpress.org/reference/functions/is_page/

  • This is actually the answer what I was looking for but the Spadilha above suggested using page templates which didn't thought of. It gives me even more freedom to personalize the page. Thank you for help thou. – Konstantin Nikkari Jan 22 '17 at 9:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.