Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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');
share|improve this question
    
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

1 Answer 1

up vote 0 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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