Home> CMS Tutorial> WordPress> body text

About showing different WordPress menu for logged in users

藏色散人
Release: 2021-02-02 15:28:29
forward
1917 people have browsed it

The following columnWordPress Tutorialwill introduce to you how to display different WordPress menus for logged in users. I hope it will be helpful to friends in need!

If you want logged-in users and non-logged-in browsers to display different menus, you can use the following code:

Login users display different WordPress menus Login users display different WordPress menus Menu

Add the following code to the current theme function template functions.php:

if( is_user_logged_in() ) { $args['menu'] = 'logged-in'; } else { $args['menu'] = 'logged-out'; } return $args; } add_filter( 'wp_nav_menu_args', 'wpc_wp_nav_menu_args' );
Copy after login

Then create two new menus, logged-in and logged-out, for login and normal browsing. or the menu displayed.

If the theme has multiple menus, you can use the following code to display different menus at the specified menu location:

function wpc_wp_nav_menu_args( $args = '' ) { if( is_user_logged_in()) { if( 'top-navigation' == $args['theme_location'] ) { // Change top-navigation to theme specific name $args['menu'] = 'logged-in'; } } else { if( 'top-navigation' == $args['theme_location'] ) { // Change top-navigation to theme specific name $args['menu'] = 'logged-out'; } } return $args; } add_filter( 'wp_nav_menu_args', 'wpc_wp_nav_menu_args' );
Copy after login

You can also use the above method to allow different user roles to display different menus content.

Original code: https://wpcodeus.com/display-different-wordpress-menu-to-logged-in-users/

The above is the detailed content of About showing different WordPress menu for logged in users. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:zmingcx.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!