0

Developing a plugin and looking to access the $wp_admin_bar global variable and it always returns null? I can output $wp_version fine?

function test()
{
    global $wp_admin_bar;
    var_dump($wp_admin_bar);
    die;
}

test();

Anybody know whats going on here?

0

You need to hook this after admin bar renders for it to work. Also, die() will make WP die.

function test()
{
    global $wp_admin_bar;
    var_dump($wp_admin_bar);
}
add_action('wp_after_admin_bar_render', 'test');

| improve this answer | |

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.