tsbain on "Adding new class to active menu item"

ساخت وبلاگ

I've successfully added a class of 'is-active' to an active sidebar menu item. My issue is, this adds the class to the 'li' element, whereas I need to add it to the 'a' element. Any thoughts on how I can accomplish this?

Here is my code:

add_filter('nav_menu_css_class' , 'current_item_nav_class' , 10 , 2);
function current_item_nav_class($classes, $item){ if( in_array('current-menu-item', $classes) ){ $classes[] = 'is-active '; } retu $classes;
}

Hi,
I'm not sure what would be the proper way to do it but adding the class with jQuery on client side is easy:

jQuery(document).ready(function($) { $('li.is-active').children('a').addClass('is-active');
});

You can also remove the class from the parent li:

jQuery(document).ready(function($) { $('li.is-active').removeClass('is-active').children('a').addClass('is-active');
});

Hope that helps.

Thanks, MyThemeShop! I'll see if I can make that go.

WordPress ...
ما را در سایت WordPress دنبال می کنید

برچسب : نویسنده : استخدام کار wpss بازدید : 305 تاريخ : شنبه 16 مرداد 1395 ساعت: 5:57