Menu item added in wp_nav_menu_items filter is never highlighted

@AlexanderFarber, there are many way to attach attribute class under wp_nav_menu link. I agree with @Sumit, adding page links in Appearance > Menu WordPress take care of current-menu-item class or current_page_item class. Also, this way is best practice to handle your nav menu in the future. Create dynamic link in wp_nav_menu Since your question related … Read more

HTML in Menu Items disappear on save

If you want to add the icon as content in a pseudoelement I would select the a by specifiyng the class you inserted in the WP menu editor (so in the li): /*hide the menu text*/ li.your-class a { visibility: hidden; } /*create the icon and make it visible*/ li.your-class a::before { content: “icon code”; … Read more

WP Walker using custom css classes

Not sure you want to do it like this, but just in case, you can use the filter nav_menu_css_class : function my_special_nav_class( $classes, $item ) { if ( is_single() && $item->title == ‘Blog’ ) { $classes[] = ‘special-class’; } return $classes; } add_filter( ‘nav_menu_css_class’, ‘my_special_nav_class’, 10, 2 ); You’ll find more example here

wp_nav_menu() with multiple Class

I don’t know what your conditions are for each class by the hook you’re looking for is nav_menu_css_class. You can use it to append classes or remove classes from each list-item <li> in the menu. /** * Modify list item classes of wp_nav_menu * – https://codex.wordpress.org/Plugin_API/Filter_Reference/nav_menu_css_class * – https://developer.wordpress.org/reference/hooks/nav_menu_css_class/ * * @param Array $classes || … Read more

Populating main menu from external JSON API

I would not bother creating a nav menu for this, I would just write a code that takes JSON as input and spits out menu markup with the data. WP’s menu data structures are quite unwieldy and aren’t too convenient to work with. There are also issues of persistence and performance (network request is usually … Read more

vertical menu bar

You can either use a filter in your functions.php file: function mytheme_nav_menu_css_class($classes, $item, $args) { if($args->theme_location == ‘secondary’) { $classes[] = ‘your-class-name’; } return $classes; } add_filter(‘nav_menu_css_class’,’mytheme_nav_menu_css_class’); Or if you go to your WP Admin, click Appearance -> Menus and then click the tab at the top “Screen Options”, you can tick CSS Classes which … Read more