Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Kevin-LeMasters-PixelParade/46786034ccf5fa98b507052fd0a7e885 to your computer and use it in GitHub Desktop.
Save Kevin-LeMasters-PixelParade/46786034ccf5fa98b507052fd0a7e885 to your computer and use it in GitHub Desktop.

How to Add Codebox Button to Admin Bar with wpcodebox,

  • create a PHP snippet
  • run snippet on page load
  • insert at admin_head

The snippet checks if logged in and only runs if true

//a little button to open codebox editor
function add_wpcodebox_link_to_admin_bar($wp_admin_bar)
{
if (is_user_logged_in()) {
$args = [
"id" => "wpcodebox-link",
"title" =>
'<img src="' .
esc_url(site_url("wp-content/plugins/wpcodebox2//logo.svg")) .
'" alt="WPCodeBox Logo" style="width: 20px; height: 20px; padding-top: 5px; display="block">',
"href" => site_url("/wp-admin/admin.php?page=wpcodebox2"),
"meta" => [
"class" => "wpcodebox-link",
"title" => "Open WPCodeBox",
],
];
$wp_admin_bar->add_node($args);
}
}
add_action("admin_bar_menu", "add_wpcodebox_link_to_admin_bar", 999);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment