1

I made a Navigation (primary) via Appearance->Menus which navigates the user to anchor tags on the side, but I also have subpages, where I want a different navigation - only with my 'Home'-button in it. Which would mean I need to get rid of the other navigation points.
I did create another sub-navigation for the subpages, but don't know how to get it up.

My header.php shows me
<php if (has_nav_menu ( 'primary') ) : ?>
Can i just do an else with another navigation?

My Theme only supports one menu though ...

Big thanks for the help! :)

  • Welcome to site :) May you please clarify your question by explaining how your theme is currently laid out? For example, is your primary navigation in header.php or elsewhere...? Also, the different navigation you referred to: how different is it? (1) entirely different, or (2) adds a one or two links to the original nav, or (3) removes one or two links...? The more information you can provide the better (and faster) answers you will get from the community here. And don't worry about being a beginner: everyone here was once a beginner. – jsmod Mar 28 at 17:12
  • PS. You can edit your question to add the details there instead of responding to this comment, that way the information will be more visible to readers. – jsmod Mar 28 at 17:15
  • 1
    Thanks for the help on the edit, @jsmod! And thanks for the nice words~ – Kalex Mar 28 at 17:33
  • Glad to assist :) Please bear with me as I ask more questions: I noticed you mentioned your theme supports one menu, yet you created a sub-navigation for your other pages. Do you mean you hard coded that sub-navigation menu in your header.php file? If yes, you might want to consider creating a child theme before you continue because any changes you make to the original (parent) theme will be gone when that theme is updated. A child theme will preserve the changes you make. – jsmod Mar 29 at 20:30
  • A quick an easy way to get a link for Home on all pages and your primary menu on only the index/home page is suggested in an answer below by Monkey Puzzle. If that works for you, please mark it as answered so others searching for the same thing can easily see the solution. – jsmod Mar 29 at 20:31
0

It doesn't sound like you need another Navigation menu.

How about something like this:

<?php if ( is_page() && $post->post_parent > 0 ) { 
   // we know we are on a sub/child page now...
   // PS. another way to handle this would be to check if you were on a particular page template or particular page ids etc.
?>
<a class="awesome-button" href="<?php echo esc_url( home_url( '/' ) ); ?>">Go home!</a>
<?php 
    // just show a link Home for the subpages...
} else {
   // now we are NOT on a subpage, so show the Primary nav menu...
   wp_nav_menu( array('menu' => 'primary') );
} ?>
  • This should go in header.php of the current theme (if it is an original theme not from the repository) or header.php of the child theme in other cases, correct? – jsmod Mar 29 at 20:43
  • 1
    You can put this in header.php or sidebar.php or any of your page templates. It all depends how your theme works and where you want it to show! – Monkey Puzzle Apr 1 at 0:42
  • 1
    Sorry for the late reply, was out cold for personal reasons. Big thx for the help, was lost at first but after I understood how and why to make subpages and not all single pages it went rather smooth! :) Now just needa figure out a way on how to best implement that home button, but the way is set~ – Kalex Apr 27 at 22:12
0

Hi @Kalex you can use the get_header for your custom header.php file. You can get the example code from here: https://developer.wordpress.org/reference/functions/get_header/ .

The combination of Template Name with Custom Header is very make sense for this case (if I understand right your question).

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.