add special menu item to primary navigation


Author Message
Flo

Posted: 7/27/2016
Quote message 

I'm developing an online shop with wordpress, the woocommerce-plugin and a theme that I've created with artisteer. Now I'm trying to add a login-link to the primary menu that changes to a logout-link if the user's logged in. This is the code that I've inserted in the child theme's functions.php:<br />

<code>add_filter( 'wp_nav_menu_items', 'my_account_loginout_link', 10, 2 );
function my_account_loginout_link( $items, $args ) {
if (is_user_logged_in() && $args->theme_location == 'primary-menu') {
$items .= '<li><a href="'. wp_logout_url( get_permalink( wc_get_page_id( 'shop' ) ) ) .'">Log Out</a></li>';
}
elseif (!is_user_logged_in() && $args->theme_location == 'primary-menu') {
$items .= '<li><a href="' . get_permalink( wc_get_page_id( 'myaccount' ) ) . '">Log In</a></li>';
}
return $items;
}</code><br/>

Unfortunatley this isn't working. The menu is set as primary navigation in the settings and in the theme's functions.php it's named like this:<br />

<code>register_nav_menus(array('primary-menu' => __('Primary Navigation', THEME_NS)));</code><br />

So I really have no idea why it isn't working. Can you maybe help me?
 
Flo

Posted: 7/28/2016
Quote message 

I was able to fix it over CSS. Not the most elegant method but it works.
I used the .logged-in class to display (or not) a menu item like this:

.logged-in ul.art-hmenu li.menu-item-218, .logged-in ul.art-hmenu li.menu-item-218>a {
display: none;
}


 
Methew Bond

Posted: 8/24/2016
Quote message 

Hi

i want to know which menu you try to add, like log in/ out link , search bar , specific wordpress menu , etc.... ????

 
Jeff

Posted: 9/16/2016
Quote message 

I have such a problem too with my Wordpress website. I created it with a template from http://www.templatemonster.com/blog/betasso-ironmass-gpl-wordpress-themes/ website. Maybe, something is wrong with the template I use? I am not good at web design really, but that templates are very nice, I guess. I need some more tips from you, guys