1

I'm trying to add a menu item to the admin top bar that has an icon. I'm adding the menu item using the following code:

$iconSVG = '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="24" height="24" viewBox="0 0 24 24"><path d="M12,16A2,2 0 0,1 14,18A2,2 0 0,1 12,20A2,2 0 0,1 10,18A2,2 0 0,1 12,16M12,10A2,2 0 0,1 14,12A2,2 0 0,1 12,14A2,2 0 0,1 10,12A2,2 0 0,1 12,10M12,4A2,2 0 0,1 14,6A2,2 0 0,1 12,8A2,2 0 0,1 10,6A2,2 0 0,1 12,4Z" /></svg>';

$wp_admin_bar->add_node(array(
        'id'    => 'test',
        'title' => 'Test',
        'href'  => 'https://example.com',
        'menu_icon'    => 'data:image/svg+xml;base64,' . base64_encode($iconSVG)
));

Based on the materials I've seen it seems as if this should work, but my menu item has no icon, just the title. So my questions are:

  1. Should this be working?
  2. What does/should it actually do? How should setting the 'menu_icon' value affect the HTML output?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.