Jump to content

What's wrong with this php line? PHP Error


halben
Go to solution Solved by halben,

Recommended Posts

I'm getting this : PHP Parse error: syntax error, unexpected T_STRING on this line of code,

$link = '<a href="' . esc_url(wp_logout_url($redirect)) . '" title="' . esc_attr(__('Logout')) . '">' . esc_attr(__('Logout')) . '</a>';

Am I missing something?

 

 

Thanks,

hal

Link to comment
Share on other sites

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>';
}
Edited by halben
Link to comment
Share on other sites

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)?

Link to comment
Share on other sites

  • Solution

I figured it out. It's silly.

 

I checked my error log and the error was posted 2 hours ago. I probably fixed it and forgot it was an old error. 

 

Sorry for your time and thanks for checking the code.

Edited by halben
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.