Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I tried to add a link manually to my menu, but something not works.

I register my menu:

register_nav_menus(
            array(
                'main_nav' => 'Main',
    ));

I try to add the item:

function add_login_logout_link( $items, $args  ) {
    if( $args->theme_location == 'main_nav' ) {
            if (is_user_logged_in()) {
                $items = '<a class="login_button" href="'.wp_logout_url(home_url()).'">Logout</a>';
            } else {
                $items = '<a class="login_button" data-toggle="modal" data-target="#login-modal-id" id="show_login" href="#">Login</a>';
            }
        }
        return $items;
}
add_filter( 'wp_nav_menu_items', 'add_login_logout_link', 10, 2 );

where is the problem?

share|improve this question
    
Inside your if condition, you are using = for $items. You need to use like this, $items .= '<a href="#">login</a>' –  Nilambar Jul 20 at 10:35
    
it doesnt help. –  Tina88 Jul 20 at 16:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.