0

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')
    {
        $user=wp_get_current_user();
        $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'); 

closed as off-topic by Nathan Johnson, Jacob Peattie, EAMann Feb 15 '18 at 15:20

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions that are too localized (such as syntax errors, code with restricted access, hacked sites, hosting or support issues) are not in scope. See how do I ask a good question?" – Nathan Johnson, Jacob Peattie, EAMann
If this question can be reworded to fit the rules in the help center, please edit the question.

1

You have an errors in

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

and

$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.