• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

UberMenu bug? fix - add custom class to an ubermenu item

abda53

Active member
Jun 10, 2022
166
211
43
On the latest version of UberMenu, there is a bug where the Custom Content -> Custom Class value is not shown on the site. In the code, the custom class value is tied in with custom content (It will only show if custom content is used). There is a spot to enter a custom class under General -> Anchor Class, but that only applies the class to the a tag, not the parent (or sub menus)

I don't know if it's an actual bug because maybe it was intended this way.. however it's not working how I needed it to (I needed a menu class on specific menus to be applied to the block li tag - without custom content.

Here is how to use the Custom Class independently from Custom Content.

/plugins/ubermenu/includes/menuitems/UberMenuItem.class.php

find: function add_class_layout_columns(){

add above it
PHP:
function get_custom_class(){
    $custom_class = $this->getSetting( 'custom_content_class' );
    if( $custom_class ){
        return ' ' . sanitize_html_class( $custom_class );
    }
    else{
        return false;
    }
}

add inside function add_class_layout_columns(), above $cols = $this->getSetting( 'columns' )
PHP:
$this->item_classes[] = $this->get_custom_class();

so it should look something like this
PHP:
    function get_custom_class(){
        $custom_class = $this->getSetting( 'custom_content_class' );
        if( $custom_class ){
            return ' ' . sanitize_html_class( $custom_class );
        }
        else{
            return false;
        }
    }  

    function add_class_layout_columns(){

        if( $this->depth > 0 ){
            $parent_submenu_type = $this->walker->parent_item()->getSetting('submenu_type_calc');
            if( $parent_submenu_type == 'flyout' ) return;    //no columns in flyouts
        }
      
        $this->item_classes[] = $this->get_custom_class();

This works, however it's not ideal since any plugin updates will remove it. It will be better extend the UberMenuItem class (if possible). I haven't spent time on that, but if I do I will update the code here
 
So glad I shared this.. just saved me hours of troubleshooting lol
 
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock