WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

I register my menu:

                '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 '14 at 10:35
it doesnt help. – Tina88 Jul 20 '14 at 16:39

Your Answer


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

Browse other questions tagged or ask your own question.