[Resolved] Customising Primary Nav Menu

Home Forums Support Customising Primary Nav Menu

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #103130
    ozraid

    Hi Tom,

    Thank you for the fantastic GeneratePress WordPress theme. It’s clean, easy-to-work with, and has offered a great entry point into WordPress.

    Being at that entry point… I’ve created a child theme for the site I’m working on at http://www.webeatthegame.com/ It’s a development site for a gaming… blog? So, I’m slowly building it as I come to terms with the wonders of WordPress actions, classes, hooks, filters, functions, and objects.

    Our current problem : We’d like to customise the primary <nav> menu displayed on the page based on :

    • Whether a user’s logged in
    • A user’s WordPress role.

    A menu has been created in the WordPress Dashboard > Appearance > Menus section for each scenario. i.e. ‘public_menu’ for users who are not logged in; ‘member_menu’ for members; and ‘admin_menu’ for site administrators.

    The functions relating to a user being logged in, and WordPress user roles I’ve got a handle on. Where I’m failing is how to replace the primary <nav> menu in the functions.php file.

    I imagine the code will need to look something like this based on my research thus far (this is a basic ‘logged in/not logged in example only for simplicity’s sake) :

    <?php
    unregister_nav_menu( 'primary' );
    
    if ( is_user_logged_in() ) {
      register_nav_menu( //some code// );
      wp_nav_menu( array ( 'menu' => 'member_menu' ) );
    }
    else {
      register_nav_menu( //some code// );
      wp_nav_menu( array ( 'menu' => 'public_menu' ) );
    }

    If you can offer any assistance, it’d be appreciated!

    Regards,
    Mark

    #103227
    Tom
    Lead Developer
    Lead Developer

    Hi Mark,

    This may be easier than using custom functions: https://wordpress.org/plugins/if-menu/

    It allows you to give conditions to each of your menu items.

    Let me know 🙂

    #103515
    ozraid

    Hi Tom,

    The plugin does exactly what I’d like, save one thing – adding a ‘Logout’ button to the menu. I believe I can figure out the code to inject a list item into the Primary Menu in the functions.php file.

    Appreciate your help!

    Regards,
    Mark

    #103560
    Tom
    Lead Developer
    Lead Developer
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.