-
AuthorPosts
-
September 8, 2015 at 6:15 pm #500051
Hello Guys,
On my pre-enfold site I used a code provided by WooThemes to show a log in button in the menu when the user is not logged in and a log out button for when, you guessed it, the user is logged in. The code provided is below (in the functions.php file of my child theme) but nothing happens. Do you have any idea?
Thanks in advance!
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 ); function add_loginout_link( $items, $args ) { if (is_user_logged_in() && $args->theme_location == 'primary-menu') { $items .= '<li><a href="'. wp_logout_url() .'">Uitloggen</a></li>'; } elseif (!is_user_logged_in() && $args->theme_location == 'primary-menu') { $items .= '<li><a href="'. site_url('wp-login.php') .'">Inloggen</a></li>'; } return $items; }
September 9, 2015 at 12:59 pm #500355Hey Luc!
does it work on a default WordPress theme? Please send us a link to the site in question. Make sure to use newest theme and WordPress version.
Best regards,
AndySeptember 9, 2015 at 3:00 pm #500464Hi Andy,
It works for standard themes, before I used “Inspire”. It worked fine.
- This reply was modified 9 years, 2 months ago by lmercx.
September 11, 2015 at 12:16 pm #501574Hey!
you are using an old version of the theme. Please upgrade to Enfold v3.2.3.
Cheers!
AndySeptember 11, 2015 at 1:24 pm #501605Hey Andy,
I’ve updated to the latest version of Enfold v3.3.2 but still no link…
Any other idea’s?
Regards Luc
September 14, 2015 at 3:07 pm #502792Hi!
please contact WooCommerce as they know their plugin best and can provide you a precise code for what you need. Try to deactivate all other plugins to check if one is causing this issue.
Cheers!
AndySeptember 14, 2015 at 3:27 pm #502810Hey!
If your using the WordPress menus in Dashboard > Appearance > Menus then switch it to this.
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 40, 2 ); function add_loginout_link( $items, $args ) { if (is_user_logged_in() && $args->theme_location == 'avia') { $items .= '<li><a href="'. wp_logout_url() .'">Uitloggen</a></li>'; } elseif (!is_user_logged_in() && $args->theme_location == 'avia') { $items .= '<li><a href="'. site_url('wp-login.php') .'">Inloggen</a></li>'; } return $items; }
“avia” is the name for our primary menu area. You can use “avia2” or “avia3” for header and footer menu areas.
Best regards,
Elliott- This reply was modified 9 years, 2 months ago by Elliott.
September 14, 2015 at 3:57 pm #502861Hello Elliot,
Thanks! This works like a charm. Can I change the order so the search icon is at the end? And the login link one before?
September 14, 2015 at 5:46 pm #502938Hi!
Change this line.
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 40, 2 );
To this.
add_filter( 'wp_nav_menu_items', 'add_loginout_link', 5, 2 );
Regards,
Elliott -
AuthorPosts
- You must be logged in to reply to this topic.