Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to add the font awesome iconfont to my menu list items, so I need to make a custom Walker.

Because the font per menu item will be different I was hoping to use the css class in the WP backend to add the name of the icon and then output that css class within the output of the walker.

Example how it should become:

$item_output .= '<a'. $attributes .'><i class="icon-' . [output css class WP backend] . '"></i>';

Does anyone know how to filter the CSS class to be able to add it to the custom walker?

Thanks and Merry Xmas!

share|improve this question
    
Why don’t you use the li CSS classes to address the items? –  toscho Dec 25 '12 at 10:25
    
Tried that too, however the icon should be placed after the anchor as you can see from the example below. –  Piet Dec 25 '12 at 15:27
    
li::after{content:"!";font-family:icon} No need for PHP. –  toscho Dec 25 '12 at 15:28
    
the FontAwesome I am using already has all kinds of that CSS by itself; on their site it says how to output the fonts and that is after the anchor and before the content. Anyways, thanks for your input! –  Piet Dec 25 '12 at 16:42

1 Answer 1

up vote 0 down vote accepted

ok, I figured it out myself.

instead of using the CSS class (as I cannot figure out how to filter it), I decided to use the description instead.

under the lines with $attributes I have added this line:

$description  = ! empty( $item->description ) ? esc_attr( $item->description ) : '';

And then I added that to the output as:

$item_output .= '<a'. $attributes .'><i class="icon-' . $description . '"></i>';

I would still be interested to hear whether it can be done with class too?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.