i have this code but its not working it throws syntax error, unexpected '}' error

function my_custom_menu_item($items, $args)
    if(is_user_logged_in() && $args->theme_location == 'primary')
        $name=$user->display_name; // or user_login , user_firstname, user_lastname
        $items .= '<li><a href="">Welcome '.$name.'</a></li>';
        $items.= //Change Password, Logout, etc
    elseif (!is_user_logged_in() && $args->theme_location == 'primary') {
        $items .= '<li><a href="'. site_url('wp-login.php') .'">Log In</a></li>';
        $items.= //Sign up, Lost Password
    return $items;
add_filter( 'wp_nav_menu_items', 'my_custom_menu_item'); 

You have an errors in

$items.= //Change Password, Logout, etc


$items.= //Sign up, Lost Password

you haven`t value for assign.Set something into $items variable or delete this strings and all will work.

  • Thank u for reply yes errors were solved but i didnt get a result – Vangari Madhu Feb 7 '18 at 10:54
  • i want to display username in primary menu – Vangari Madhu Feb 7 '18 at 10:54
  • look here add_filter( 'wp_nav_menu_items', 'my_custom_menu_item' );. You use 2 parameters in your function and you need add fourth argument in add_filter();. Change your hook call to add_filter( 'wp_nav_menu_items', 'my_custom_menu_item'); – Maxim Sarandi Feb 7 '18 at 11:09
  • i cant understand can u give more information for this problem – Vangari Madhu Feb 7 '18 at 11:36
  • See here If you accept more than 1 parametr in your function ($items, $args for your situation), you should set accepted_args to parameters count. for you just replace your add_filter( 'wp_nav_menu_items', 'my_custom_menu_item' ); to add_filter( 'wp_nav_menu_items', 'my_custom_menu_item', 10, 2); and all will work – Maxim Sarandi Feb 7 '18 at 12:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.