WPML – menu only shows icons in default language

Home Forums Pro Support WPML – menu only shows icons in default language

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #67922
    Paul MullerPaul Muller
    Participant

    Hi, we have set icons for our menu items but are using WPML for our sites translation (including menus). Unfortunately it looks like you are recording the icons we select against the menu item ID’s and when it’s using the translated version of the menu, they no longer match up. Any thoughts on how this can be fixed?

    Also, you do not appear to support FontAwesome’s “light” (pro) icon sets in your drop-down or in the CSS (we have our own license for FontAwesome pro).

    Thanks.

    #67929
    Peter FeatherstonePeter Featherstone
    Participant

    Hey Paul,

    Yes they are matched by ID. I’m not sure how else that could be done any other way, do you have any suggestions on that front?

    You can disable the scripts included by my plugin in the Technical section and then select custom from the drop-down and include your own.

    I hope that helps

    Peter

    #67928
    Paul MullerPaul Muller
    Participant

    We ended up doing a workaround by using the nav_menu_item_title hook (our function is included below).
    By adding a class to the wordpress menu item in the format like this “ico-fas-user”, the function will prepend the correct span to the title and the alternate naming of the class on the menu item means it will have no effect in the wrong place.

    /**
     * Add icons to custom nav
     */
    function my_nav_menu_item_title( $title, $item, $args, $depth ){
    
      foreach($item->classes as $class) {
        if(substr($class, 0, 4) == 'ico-') {
          $class = str_replace(array('far-', 'fas-', 'fal-', 'fab-'), array('far fa-', 'fas fa-', 'fal fa-', 'fab fa-'), substr($class, 4));
          $icon = '<span class="'.$class.'"></span>';
          $title  = $icon.$title;
          break;
        }
      }
    
      return $title;
    }
    add_filter('nav_menu_item_title','my_nav_menu_item_title',10,4);
    #67927
    Peter FeatherstonePeter Featherstone
    Participant

    Hey Paul,

    Excellent and thanks for sharing it here!

    All the best

    Peter

    #67926
    Joseph BouqdibJoseph Bouqdib
    Participant

    Hello,

    I’ve got the same problem, but i’m using Polylang.
    Would that workaround work in my case aswell? And if so, how do I implement it?

    Regards,
    Joseph

    #67925
    Peter FeatherstonePeter Featherstone
    Participant

    Hey Joseph,

    I wouldn’t know I’m afraid, you would have to try it to see. The code is in the post above from Paul, you can just copy and paste it.

    Please let me know how you get on.

    Peter

    #67924
    Joseph BouqdibJoseph Bouqdib
    Participant

    Thanks for the quick answer.
    Where do i paste that code to?
    I haven’t quite understood it yet 🙂

    #67923
    Peter FeatherstonePeter Featherstone
    Participant

    Hey Joseph,

    Paul would know exactly but I’d expect it just goes in the themes functions.php file along with the other customisations.

    Please let me know

    Peter

Viewing 8 posts - 1 through 8 (of 8 total)
  • The topic ‘WPML – menu only shows icons in default language’ is closed to new replies.