I was trying to find a way to do the exact same thing.
However, I’m using the “get_template_part” method outlined in the article referenced above (http://blog.teamtreehouse.com/perfect-wordpress-inline-svg-workflow).
I’m not too familiar with custom walkers, but it sounds like a reasonable solution. Basically, what I want is this code for each menu item:
<li><a href="[menu item url]"><?php get_template_part( 'img/icons/inline', '[slug of menu item].svg' ); ?>Menu Item</a></li>
So that an inline SVG icon gets inserted right before the text of the menu item, and that icon is selected based on the slug for the menu item itself. So that a menu item of “Product List” that has a page slug of “product” would grab the img/icon/inline-product.svg.php template part.
Any help or suggestions would be appreciated!
Alicia, I would love to see what you came up with for a custom walker in this regard. Did you end up finding a workable solution? Care to share please (blog article, or Gist)?
Hi, Damon! I’ve seen two successful ways of inserting icons before menu items in WordPress:
WPMU DEV posted this tutorial that uses the FontAwesome icon font: http://premium.wpmudev.org/blog/add-icons-wordpress-menus
(I’ve had great success with fontastic.me for creating custom icon fonts if you want to use your own icons.)
I also came up with a messy but effective solution that you can see here: http://rebeccabgiddings.com/2014/09/adding-svg-icon-wordpress-menu-items
Hope this helps!
Thanks rbgiddings!
I’m trying to steer clear of icon fonts, because they’re not rendered as consistently and was having issues with Font Awesome specifically.
Inline SVG is way to go, and I forgot that you can actually add HTML to the Navigation Label as you demonstrate in your post. Thanks, and that is a big help!
Also, @gregrickaby wrote a helpful template function to allow you to easily add in themes if you’re interested: https://github.com/WebDevStudios/_s/blob/svg/inc/template-tags.php#L270