- This topic has 3 replies, 2 voices, and was last updated 7 years, 9 months ago by
Tom.
-
AuthorPosts
-
April 28, 2015 at 4:45 am #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,
MarkApril 28, 2015 at 8:15 am #103227Tom
Lead DeveloperLead DeveloperHi 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 ๐
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentApril 28, 2015 at 4:50 pm #103515ozraid
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,
MarkApril 28, 2015 at 10:53 pm #103560Tom
Lead DeveloperLead DeveloperThis article looks like it could be helpful ๐ https://phpmatters.com/add-login-logout-link-to-wordpress-menu/
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.