I've created a menu that, instead of plain text, needs to have icons. Unfortunately the "CSS Classes" option provided by WP adds the class to the li
rather than the a
so the icon won't be clickable if added there. Also, if I add a menu item without a title (because my menus should be nothing but icons) the menu item disappears completely when saving the menu.
To solve this I've simply set the "Navigation Label" to <span class="icon-facebook" title="Facebook"></span>
. This works fine and I've done it this way for ages.
What I noticed today however is that if the user administrating the menu is not an admin, he is unable to save a menu item with HTML in its label. This results in the HTML being stripped, the "Navigation Label" being empty and thus WP removing that menu item completely upon saving the menu.
Non-admins usually do not have access to the Menu Admin screen, but I've given Editors that capability using:
$editorRole = get_role('editor');
if (!$editorRole->has_cap('edit_theme_options')) {
$editorRole->add_cap('edit_theme_options');
}
Why does WP strip the HTML and how can I prevent it from doing so?