WP Admin Bar – PHP inside of title Argument

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

Here is what some of my php looks like for the custom admin bar link I created:

$wp_admin_bar->add_menu( array(
'id' => 'ab-sh-current-theme',
'parent' => 'my_custom-menu',
'title' => 'Theme Name',
'href' => false
) );

I wish to insert a snippet of PHP where you see Theme Name, like so: 'title' => 'Theme Name',

Get Current Theme WP Codex

Add Menu Function Reference

$theme_name = get_current_theme();
echo $theme_name;

  • Sajid
    • DEV MAN’s Sidekick

    Hi Webmaster! Hope you are doing good and thanks for your question :slight_smile:

    To display name of current theme in admin bar, add below code in funtions.php file or your theme or child theme (recommended).

    function wpmu_current_theme_name() {
    global $wp_admin_bar, $wpdb;

    $current_themename = wp_get_theme();

    $wp_admin_bar->add_menu( array( 'id' => 'current_theme', 'title' => $current_themename, 'href' => FALSE ) );
    add_action( 'admin_bar_menu', 'wpmu_current_theme_name', 1000 );

    Let me know if its not working or you need further support :slight_smile:

    Cheers, Sajid

  • Webmaster
    • Flash Drive

    You are very helpful! I am feeling healthy @Sajid – I hope you are good too my friend!

    // Theme Name
    $current_theme = wp_get_theme();
    $wp_admin_bar->add_menu( array(
    'id' => 'wp-admin-bar-theme-name',
    'parent' => 'my_custom-menu',
    'title' => $current_theme->get('Name'),
    'href' => false
    ) );

  • Sajid
    • DEV MAN’s Sidekick

    Hi Webmaster! You are welcome :slight_smile:

    No we do not have simple mark as resolved button yet. However you can simply leave it as it is if the previous staff answer solved your problem and it will be considered as resolved.

    Take care and have a great weekend :slight_smile:

    Cheers, Sajid

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.