0

When I try to title an admin menu link # or #, I get a fatal error before the admin menu is loaded:

Fatal error: Cannot access empty property in /path/to/wp-includes/class-wp-admin-bar.php on line 79

The error does not occur if I use an alphanumeric menu title like My admin link. This is the code I am using in functions.php:

function my_admin_bar_menu() {

    global $wp_admin_bar;
    if ( !is_super_admin() || !is_admin_bar_showing() )
        return;

    $wp_admin_bar->add_menu( array(
    'title' => __( '#'),
    'href' => admin_url('myurl.php')));

}

add_action('admin_bar_menu', 'my_admin_bar_menu');
  • Did you try using the HTML encoding instead ? # – zac Sep 19 '11 at 4:41
  • Yep, as noted in the first sentence. – supertrue Sep 19 '11 at 23:44
  • Oop! sorry, dont know how i missed that. – zac Sep 20 '11 at 15:48
0

I figured out the problem: You must specify an ID in the add_menu array if the title is not alphanumeric. So, this code worked:

function my_admin_bar_menu() {

    global $wp_admin_bar;
    if ( !is_super_admin() || !is_admin_bar_showing() )
        return;

    $wp_admin_bar->add_menu( array(
    'title' => __( '#'),
    'id' => __( 'my_menu_item'),
    'href' => admin_url('myurl.php')));

}

add_action('admin_bar_menu', 'my_admin_bar_menu');

The only change is the addition of the line containing 'id'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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