Jump to content

What's wrong with this php line? PHP Error


halben

Recommended Posts

It's probably the line before that one as that one is OK.  Try pasting it here in code tags and the syntax highlighting should show the error.  Also, if you use a good editor it should highlight errors.

Here is what I have:

add_filter('wp_nav_menu_items', 'custom_menu', 50, 2);
function custom_menu($items, $args) {
if (is_admin() || $args -> theme_location != 'top_menu')
    return $items;

if (is_user_logged_in()) {
$user = wp_get_current_user();
$firstName = $user -> user_firstname;
$lastName = $user -> user_lastname;
$items .= '<li id="user-name" title="Edit" ><a href="' . esc_url(site_url('/profile')) . '">' . esc_attr($firstName) . ' ' . esc_attr($lastName) . '</a></li>';


$link = '<a href="' . esc_url(wp_logout_url($redirect)) . '" title="' . esc_attr(__('Logout')) . '">' . esc_attr(__('Logout')) . '</a>';
} else {
$link2 = '<a href="' . esc_url(site_url('/register')) . '" title="' . esc_attr(__('Register')) . '">' . esc_attr(__('Register')) . '</a>';
$items .= '<li id="register-link" class="menu-item menu-type-link">' . $link2 . '</li>';


$link = '<a href="' . esc_url(wp_login_url($redirect)) . '" title="' . esc_attr(__('Login')) . '">' . esc_attr(__('Login')) . '</a>';
}


return $items .= '<li id="log-in-out-link" class="menu-item menu-type-link">' . $link . '</li>';
}

nope, the code in the post does not produce that syntax error.

 

some possibilities -

 

1) your actual code contains some smart/curly quotes or other non-ascii characters in the php code, and when you paste it into this forum, they are converted to straight quotes,

 

2) the actual file/line where the error is at is not the code you are looking at (perhaps you have multiple versions at different paths.)

 

has this code ever worked? are you typing this code or are you copy/pasting this from some web site (code is often 'published' using characters/encoding that isn't valid code)?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.