December 14, 2020 at 3:25 pm
Hello Team Kadence!
I need a bit of help with changing the walker class. Your code has:
$custom_classes = get_post_meta( $item->ID, '_menu_item_classes', true );
if ( $custom_classes ) {
foreach ( $custom_classes as $custom_class ) {
if ( strpos( $custom_class, 'icon' ) !== false || strpos( $custom_class, 'kt-icon' ) !== false ) {
$icon_class = $custom_class;
} else {
$classes[] = $custom_class;
}
}
}
If I change the needles, I can get my class to show up, but I can’t seem to get this function to work inside my child theme. I’m using Font Awesome and I changed the code to:
$custom_classes = get_post_meta( $item->ID, '_menu_item_classes', true );
if ( $custom_classes ) {
foreach ( $custom_classes as $custom_class ) {
if ( strpos( $custom_class, 'fab' ) !== false || strpos( $custom_class, 'fa-' ) !== false ) {
$icon_class = $custom_class;
} else {
$classes[] = $custom_class;
}
}
}
as a test. It works – but only when I modify the parent theme (which I don’t want to do). Can you help me with this?
FYI: right now, if I put the class as fab fa-facebook-f icon-facebook (as a test) the output is:
<li class=" menu-item-71 menu-item menu-facebook fab fa-facebook-f" aria-hidden="true"><a href="#"><i class="icon-facebook"></i><span>Facebook</span></a></li>
I want ‘fa-facebook-f’ to be part of <i class="icon-facebook"></i>.
Ideally, I’d like it to work like this:
1. If fa-*whatever* is present, use this class.
2. If no fa-*whatever* is present, use icon-*whatever* if present.
3. If both are not present, work as normal.
I’m not sure I’m explaining correctly so please ask me any questions you want.