1

Want to add the CSS class added to the Wordpress menu as shown below CSS Meny

to my menu

      wp_nav_menu( array( 
        'theme_location'    => 'header', 
        'container'         => false, 
        'items_wrap'        => '%3$s', 
        'after'             => '<span class="icon-thumbnail"><i class="fa "></i></span>'
      )); 

To create

<li>
  <a href="/">Dashboard</a> 
  <span class="icon-thumbnail">
  <i class="fa fa-reorder"></i>
  </span>
</li>

So, add the CSS class that was added to the menu_item within the Wordpress Admin to the <i class="fa "></i> in my menu. Therefore, looking like <i class="fa fa-reorder"></i>

1
  • Explain more what is not happening? What exactly you want? Commented Aug 19, 2017 at 8:08

1 Answer 1

1

Do this

wp_nav_menu( array( 
     'theme_location'    => 'header', 
     'container'         => false,
     'items_wrap'        => '%3$s',
));

In wp admin in css input box put this class

fa fa-reorder

This should fix the issue you need to add append fa class to add fontawesone icons.

EDIT: This is the walker for bootstrap.

https://github.com/wp-bootstrap/wp-bootstrap-navwalker

Edit the code as per your need

This part in the walker is to be edited for fixing your issue.

if ( ! empty( $item->attr_title ) ) {
  $pos = strpos( esc_attr( $item->attr_title ), 'glyphicon' );

  if ( false !== $pos ) {
      $item_output .= '<a' . $attributes . '><span class="glyphicon ' . esc_attr( $item->attr_title ) . '" aria-hidden="true"></span>&nbsp;';
  } else {
      $item_output .= '<a' . $attributes . '><i class="fa ' . esc_attr( $item->attr_title ) . '" aria-hidden="true"></i>&nbsp;';
  }
} else {
    $item_output .= '<a' . $attributes . '>';
}

This should fix the issue

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. However, I need the class to be added to the '<i class="fa ">', so it outputs as '<i class="fa fa-reorder">' within the '<span class="icon-thumbnail">'. Therefore, whether it is with css input 'fa fa-reorder' or 'fa-reorder' I m still not achieving the outcome I need.
You need to create a walker for that. Are you using bootstrap?
@Darren Mathers did that work? If yes mark this as solved.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.