Problems with multiple menus
-
I’m making menus for logged off/in users. One or the other will show depending on whether they are logged in. It’s simple code,
// Navigation menu if (is_user_logged_in() ) { register_nav_menus( array( 'main' => __('User'), } else { 'visitor' => __( 'Visitor' ) ) ); };But it keeps returning this error:
Parse error: syntax error, unexpected ‘}’, expecting ‘)’ in C:\xampp\htdocs\mysite\wp-content\themes\THEME\functions.php on line 225Line 255 being the one containing
} else {It’s pretty insane really. Any help? WP 3 menus amuse me by making me feel like a noob.
-
I’m not a code genius but here:
register_nav_menus( array( 'main' => __('User'), } else {you have three open parentheses and one closed parenthesis.
I know you have the closed parentheses later but the error message is saying that it is expecting it sooner, so you may need them in both places.
It’s returning the same error… The code you gave me is the exact same one I have. I can’t close the tags sooner then they already are (At least I assume so). If I do, the visitor menu will be completely excluded.
The way you have it written, if the user is not logged in, they don’t get the
register_nav_menus( array(part. Do you want it that way?
You also need to have the final } in a place where it will apply to both conditions, so your closing parentheses may need to be after that.
I don’t want the logged off user to see the
'main' => __('User'),and I don’t want the logged in users to see the'visitor' => __( 'Visitor' )
But rather to see their respective menus.When I change the location of the
if (is_user_logged_in() )statement and change it to:register_nav_menus( array( if (is_user_logged_in() ) { 'main' => __('User'), } else { 'visitor' => __( 'Visitor' ) ) ); };I get this error instead:
Parse error: syntax error, unexpected T_IF, expecting ')' in C:\xampp\htdocs\mysite\wp-content\themes\THEME\functions.php on line 225I’m assuming that your code includes
<?phpand?>in some places.Yes, but several items/attributes are inside one
<?php ?> tag
like// Theme features tb_add_theme_feature('query_vars', 'scheme'); // Navigation menu if (is_user_logged_in() ) {Those two are under the same tag
The topic ‘Problems with multiple menus’ is closed to new replies.