Viewing 21 posts - 1 through 21 (of 21 total)
  • Author
    Posts
  • #333356

    Hi enfold team:

    I wonder if there is any way to add the enfold icons of my choosing above the menu link?

    Thanks in advance.

    BR//

    Heng GAO

    #333357

    Hey Heng!

    You can add Icon element under Content elements in ALB and then copy HTML code – http://i.imgur.com/Loqd5it.png and paste it in label field while adding new link in Appearance > Menus. Make sure to remove “style” attribute

    Cheers!
    Yigit

    #333804

    Hi Yigit:

    Thanks for your solutions. As I was trying this solution, there is a extra node added to the HTML code. Looks similar below:

    <li id=”menu-item-755″ class=”menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children menu-item-top-level menu-item-top-level-1 dropdown_ul_available”>
    <span class=”avia-bullet”>… ###This is automatically added
    <span class=”dropdown_available”></span><span class=”avia-menu-fx”><span class=”avia-arrow-wrap”><span class=”avia-arrow”>

    The problem here could be when I add a link or a page to the menu, the node is added automatically which in my case will causing the icon menu item 80px blow the expected position. Do you think there is anyway around this? Or am I doing this the wrong way?

    Thanks a lot.

    #333987

    Hi!

    Can you post the link to your website please? If you do not mind, please create a temporary admin login as well

    Cheers!
    Yigit

    #334164

    Hi Yigit:

    I did not put anything online yet, but only doing test preparation on local server. I am just thinking you must have met many situations which requires adding html code to the MENU lable, If you can just try to embed any icon html code to the menu, you will noticed that there is a “\” node which includes the href attribute from custom link added automatically above the embed code by the menu settings.

    #334166

    Hi Yigit:

    Sorry, the \<\a\> is automatically changed by the forum here.

    #334884

    Hey!

    Can you please try adding this HTML code to menu label – http://pastebin.com/ZP8paZg3
    It does work fine on my end

    Regards,
    Yigit

    #970450

    Hi there,
    this is working for me as well :-) But my problem ist: I do not know how to change the
    data-av_icon=””
    into the icon I want!
    I went to fontello and tried to copy the code in the”Customize Code” Tab, but it did not work :-(
    Any idea or help?

    Thank you!

    #971527

    Hi,

    Have you tried using the actual icon shortcode instead of extracting the rendered html? That should work.

    Best regards,
    Ismael

    #1437009
    This reply has been marked as private.
    #1437040

    Hi StephenStamp,

    The Icon element is an element in the Enfold Layout Builder, please create a new page then drag the element in question to your layout.

    Best regards,
    Rikard

    #1437056
    This reply has been marked as private.
    #1437108

    Hi,
    As I understand you would like to be able to add icons next to your main menu items, here is a easy was to add icons like this:
    Enfold_Support_5056.jpeg
    We will add this function to the end of your child theme functions.php file in Appearance ▸ Editor or if you are not using a child theme you could use the WP Code plugin then add a new snippet, in the top right corner use the PHP snippet as the code type:
    Enfold_Support_2680.jpeg
    then add this code and save:

    function enqueue_font_awesome() {
        wp_enqueue_style('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css');
    }
    add_action('wp_enqueue_scripts', 'enqueue_font_awesome');
    function add_icon_to_menu_item($item_output, $item, $depth, $args) {
        $custom_classes = implode(' ', $item->classes);
        preg_match('/menu-item-icon-([^ ]+)/', $custom_classes, $matches);
        if (!empty($matches[1])) {
            $icon_class = esc_attr($matches[1]);
            $icon = '<i class="fa ' . $icon_class . '"></i>';
            $position = strpos($item_output, '<span class="avia-menu-text">');
            if ($position !== false) {
                $item_output = substr_replace($item_output, $icon, $position, 0);
            }
        }
        return $item_output;
    }
    add_filter('walker_nav_menu_start_el', 'add_icon_to_menu_item', 10, 4);

    Please ensure to copy the code from the forum and not an email notification so the symbols are not converted.
    Then add this CSS in your Enfold Theme Options ▸ General Styling ▸ Quick CSS field:

    #top #header li.menu-item > i ~ a {
    	display: inline-block;
    }
    #top #header li.menu-item > i:before {
    	color: #fff;
    }
    .av-main-nav li[class*="menu-item-icon-"] > a > i ~ .avia-menu-text {
        border-left-style: none;
        border-left-width: 0;
        padding-left: 13px;
        margin-left: -6px;
    }
    #av-burger-menu-ul li > a > i ~ .avia-menu-text {
    	  padding-left: 13px;
        margin-left: -6px;
    }
    

    Please note that you may want to change the color, in this example I’m using white because my menu is dark.
    Then go to your menus and ensure that the Custom Class field is enabled for your menu items:
    Enfold_Support_5045.jpeg
    If you don’t see it go to the Screen Options and enable it.
    Enfold_Support_5048.jpeg
    Now we will use the Font Awesome icons because it will be easier to use a class name to determine the icon used in the custom class field, the built-in entypo-fontello icons don’t use class names the same way so it would be a little trickier for you. The function adds the icon next to the menu item based on the class used in the menu item custom class field.
    Use this format: menu-item-icon-fa-home the first part menu-item-icon- tells the function that a icon will be used, and then the Font Awesome icon code is appened to the class fa-home, for example:
    Enfold_Support_5050.jpeg
    these are the classes I used in this example:
    menu-item-icon-fa-home
    menu-item-icon-fa-star
    menu-item-icon-fa-life-ring
    menu-item-icon-fa-users
    menu-item-icon-fa-phone
    menu-item-icon-fa-bullhorn

    This also works for the sub-menu items:
    Enfold_Support_5054.jpeg
    and the mobile menu:
    Enfold_Support_5052.jpeg

    Best regards,
    Mike

    #1438020

    Hi everyone.
    Mike solution seems awesome but I can’t figure out how to adapt it for secondary menu.

    Can you give me a clue ?

    Best regards

    #1438040

    Hi,
    It was working in the secondary menu for me above:
    Enfold_Support_5054.jpeg
    If you mean the Fullwidth Sub Menu element, then you must choose a existing menu to use:
    Enfold_Support_5132.jpeg
    Otherwise check the steps carefully and if you still have trouble open a new thread with an admin login so we can check, posting a admin login here will not be private because this is not your thread.

    Best regards,
    Mike

    #1438359

    I have found this this forum post and have successful implement it to header menu (main menu). That was possible for me according to the instructions provided by the moderator “Mike” on “March 13, 2024 at 2:09 am”. But I’m not able to add this to the footer menu. So the question is how to add this “font awesome icons” to footer widget (footer menu) as well?

    #1438363

    Hi,
    It sounds like you followed the instructions above and the main menu now has the icons next to the items, so the next step is to create a footer menu in the menu page
    Enfold_Support_5168.jpeg
    and then ensure that you have added the classes to the footer menu items, just like the main menu:
    Enfold_Support_5170.jpeg
    then choose the footer menu for the footer location:
    Enfold_Support_5172.jpeg
    and you should see the icons next to the items:
    Enfold_Support_5174.jpeg
    Please note that the footer menu doesn’t allow a drop down menu so you won’t see sub-menu items.

    Best regards,
    Mike

    #1438367

    Ok, I guess I phrased it wrong.

    It works, but it’s not what I wanted.

    I would like to display the icons in the menus that I have inserted into the “Footer Column” using widgets.

    I have already set everything up.

    The menus are already displayed in the “Footer Column”.

    However, no icons will be displayed in these menus when using this method.

    #1438385

    Hi,
    I believe that you are referring to the Widget Navigation Menu,
    Enfold_Support_5176.jpeg
    to add the icons to those menu items add this CSS in your Enfold Theme Options ▸ General Styling ▸ Quick CSS field:

    #menu-footer-menu li.menu-item > i ~ a {
    	display: inline-block;
    }
    #menu-footer-menu li.menu-item > i:before {
    	color: #fff;
    }

    Then add this code to the end of your child theme functions.php file in Appearance ▸ Editor, if you are not using a child theme you could use the WP Code plugin then add a new snippet, in the top right corner use the PHP snippet as the code type:
    Enfold_Support_2680.jpeg
    then add this code and save. Please ensure to copy the code from the forum and not an email notification so the symbols are not converted.

    function add_icon_to_widget_menu_items() { ?>
      <script>
    document.addEventListener("DOMContentLoaded", function() {
        const menuItems = document.querySelectorAll('#menu-footer-menu li'); 
        menuItems.forEach(function(item) {
            let classes = item.className.split(/\s+/);
            let iconClass = classes.find(c => c.startsWith('menu-item-icon-'));
            if (iconClass) {
                let iconName = iconClass.replace('menu-item-icon-', '');
                item.innerHTML = '<i class="fa ' + iconName + '"></i> ' + item.innerHTML;
            }
        });
    });
    </script>
      <?php
    }
    add_action( 'wp_footer', 'add_icon_to_widget_menu_items', 99 );

    Enfold_Support_5178.jpeg

    Best regards,
    Mike

    #1438449

    It worked.
    Thank you for the fast and competent support!

    #1438464

    Hi,
    Glad we were able to help, if you have any further questions please create a new thread and we will gladly try to help you. Thank you for using Enfold.

    Best regards,
    Mike

Viewing 21 posts - 1 through 21 (of 21 total)
  • The topic ‘How to add a enfold icon to the menu link’ is closed to new replies.