• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2784

Original Genesis Tutorials & 6000+ Guaranteed Code

Snippets

  • Consultation
  • Full Access
  • Log in

Change Nav Menu For Specific Page In Any Theme

This PHP code enables you to change the primary nav menu for any permalink slug or i.d.

Register for full access


1. primary – This is the Theme Location the default menu is assigned to. Go to Appearance > Menus > Manage Locations to configure this setting.

2. default – This is the name of the menu. Go to Appearance > Menus > Edit Menus to create a menu named default.

3. about – This is the permalink slug for the page named About. You can use the slug for any other page or the post/page/tag slug in its place. You can also change the conditional tag to any other.

4. custom – This is the name of the conditional menu which you can create. Go to Appearance > Menus > Edit Menus to create a menu named custom. When you click on the menu item named about, the menu with the name custom will display rather than the menu named default.

The code also includes the PHP comparison operator == and the basic assignment operator = which is used to write a value to a variable.

Hope you find this code and tutorial useful and and look forward to any questions you may have about this topic in the comments below.

Similar Posts

  • Remove Navigation Menu From Specific Page
  • Conditionally Remove Your Primary & Secondary Nav Menu
  • How To Display A Different Nav Menu For Logged In Members & Logged Out Visitors
  • Change Nav Menu For Specific Page In Header.php
  • Display Different Nav Menu’s On Pages & Posts In Genesis

Nav Menu

Reader Interactions

Comments

  1. Carlson007 says

    September 10, 2015 at 1:30 pm

    Hi Brad,

    Thanks so much for all your snippets and tutorials; I use them every time. This argument works for the primary navigation location. What if I want to do same for the secondary navigation?

    Log in to Reply
    • Brad Dalton says

      September 10, 2015 at 9:46 pm

      Change primary to secondary in the code.

      Log in to Reply
  2. Joe Young says

    July 26, 2014 at 7:23 pm

    Just wanted to say thank you! Worked great. Even tweaked it with some “if in_category” stuff to show on posts. Was a great find.

    Thanks again.

    Log in to Reply
  3. sam says

    June 11, 2014 at 11:10 am

    Hi this is great works perfectly – I am trying to add a second set of arguments to display another menu for a new set of pages on a regional site – can you help. I tried this but getting errors – first part works fine for au – how do I add a second array of pages

    Log in to Reply
    • Brad Dalton says

      June 11, 2014 at 1:02 pm

      Hi Sam

      Please paste PHP code in a Github Gist and link to it from here. Thanks

      Log in to Reply
  4. Herb Trevathan says

    February 6, 2014 at 12:30 pm

    This will come in handy! Thanks Brad. I use your snippets all the time.

    Log in to Reply
    • Brad Dalton says

      February 6, 2014 at 12:36 pm

      You’re welcome Herb.
      More on this topic coming soon.

      Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags
 

Loading Comments...
 

You must be logged in to post a comment.