0

I wish to echo the current theme in text in my WP Admin Bar sub menu.

How would I go about display a snippet of PHP inside the 'title' => 'php snippet here', ?

http://codex.wordpress.org/Function_Reference/get_current_theme http://codex.wordpress.org/Function_Reference/add_menu

$theme_name = get_current_theme();
echo $theme_name;
2
  • You did not try this ? $wp_admin_bar->add_menu( array( 'id' => 'node_id', 'title' => get_current_theme() ) );
    – Sumit
    Commented May 23, 2015 at 9:42
  • I just tried it, and a few other thigs like wrapping that in ' plus adding , as well as copy / pasting and replacing.
    – Uncle Iroh
    Commented May 23, 2015 at 9:58

1 Answer 1

0

First thing get_current_theme() is deprecated since version 3.4 you need to use wp get theme() to get the current theme name.

And about add_menu() you can only use it at action hook admin_bar_menu as codex say about it:

This is not a function. It is a method of the $wp_admin_bar global (an instance of WP_Admin_Bar), which may not exist except during the 'admin_bar_menu' hook.

Working example

function foo_test_menu() {
    global $wp_admin_bar;
    $current_theme = wp_get_theme();
    $wp_admin_bar->add_menu( array(
        'id' => 'your_menu_id',
        'title' => $current_theme->get('Name')
    ) );   
}
add_action('admin_bar_menu', 'foo_test_menu');
1
  • 1
    very helpful! Thanks for the semantics. Once I reach 15 rep, I'll be back to vote up your answer...hooah!
    – Uncle Iroh
    Commented May 23, 2015 at 10:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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