给wp_nav_menu的li和a添加class
Published
2022-11-23
浏览次数 : 140
// add classes on li
function codedocs_add_classes_on_li($classes) { $classes[] = 'nav-item'; return $classes;
}add_filter( 'nav_menu_css_class', 'codedocs_add_classes_on_li' );
//add active to current item
function codedocs_add_active_to_nav_class($classes) {
if (in_array('current-menu-item', $classes)) { $classes[] = 'active'; }
return $classes;}add_filter( 'nav_menu_css_class', 'codedocs_add_active_to_nav_class' );
//add classes on anchor of wp nav menu
function codedocs_add_classes_on_anchor($atts) { $class = 'nav-link'; $atts['class'] = $class; return $atts;}
add_filter('nav_menu_link_attributes','codedocs_add_classes_on_anchor');
- 标签1
- 标签1
- 标签1