Add icon fonts to your WordPress menu

I wanted to integrate an icon font into a WordPress theme to use for sort of a “social” menu (links to the site owner’s Facebook/Twitter/etc profiles, represented by the icon of the respective service).

Adding the icon font isn’t the problem (drop in the font files, include the css and done) but adding the classes to the menu location? Turns out that’s easier than you might think πŸ™‚

wp_nav_menu takes a number of parameters, 2 of which are link_before and link_after.

The icon font I was for this was the Symbol Set Social Regular. The icons are represented by a unicode string, a css class or a keyword (wrapped in a global css class).

 
wp_nav_menu(array( 
'theme_location' => 'secondary',
'menu_class' => 'nav-menu',
'container_id' => 'top-right-menu',
'fallback_cb' => false,
'link_before' => '<i class="ss-icon">',
'link_after' => '</i>'
 )); 

This wraps each menu item in the correct tags and it the text you put in the title field for that menu item matches the icon font (in this case the words “Facebook”, “Twitter”, “Instagram”, etc), it’ll render that menu item as an icon instead of text. Easy is pie. πŸ™‚

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s