Got it to work, finally!
Nothing like a good sleep to restart your brain 🙂
Updated code that works:
$item_output = $args->before;
if( $item->object == 'category' ) {
$category = get_category( $item->object_id );
$category_color = get_field( 'category_color', $category);
$item_output .= '<a style="color:' . $category_color . ';"'. $attributes .'>';
} else {
$item_output .= '<a'. $attributes .'>';
}
$item_output .= $args->link_before . apply_filters( 'the_title', $item->title, $item->ID ) . $args->link_after;
$item_output .= ( $args->has_children ) ? '<i class="fa fa-angle-down"></i></a>' : '</a>';
$item_output .= $args->after;
Related Posts:
- Custom Nav Walker menu – Display category count
- Create menu / submenu from category subcategory and posts
- Custom Walker for wp_list_categories
- Hooking to walker_nav_menu_start_el to insert list of subpages
- How to remove an item from a custom Walker_Nav_Menu
- How to create an automatic MultiColoumn MegaMenu with Categories WordPress
- Admin Panel – Disable Moving Selected Terms To Top of Metabox
- Reflect nested categories in appearance > menus
- Category menu item and its last 10 posts as sub-menu
- Is there a function to cause empty categories not to show in menus?
- Keep active class in post page
- Auto add pages to category menu
- How to show empty category in admin menus search
- Add custom taxonomy terms to WordPress menu dynamically & append #slug to url
- Display WooCommerce product categories in a 4 columns custom menu [closed]
- Render Selected Categories in Admin Edit Post Screen differently
- Automatically add product_categories to nav_menu
- Add Product categories to WordPress menu without losing hierarchy
- Custom Category/Subcategory structure
- Show thumbnail for category?
- Add a specific category at a specific place to the menu that uses wp_list_pages
- Multiple menu items highlighted
- wp_nav_menu not highlighting the current category when viewing a single post
- Show recent posts in menu?
- Show Different Custom Menu on Different Category Pages
- Open subcategories in submenu on click in primary menu
- How to add Categories to the top menu of the website?
- Implementing a tricky wordpress menu (nested categories + thumbnails)
- Nav menu category links not showing
- Show number of articles in menu
- How to show only one category in breadcrumb navigation
- Automatically adding categories and authors in custom menu?
- Hard coded main navigation
- Highlight wp_nav_menu when category is selected
- Class active for Archive link – looped out
- Why does the argument list_only do on Walker_Category_Checklist::start_el?
- Menus don’t work after 4.4 [closed]
- category permalinks
- wp_list_categories in in nav_menu
- Different menu navigation per category
- WP admin broken. Not saving catgories or adding categories to menu
- Creating Category Specific menus
- Create menu locations for each category in wordpress
- Building Menu from Woocommerce Product Categories
- Show subcategories on a parent category page
- Admin: Navigation Menus do not show empty categories/taxonomies in the list’s search tab
- Give Children Unique ID’s
- Change div background acording to the selected category
- How to modify the output of wp_terms_checklist when used within the built-in category metabox on edit posts?
- wp_list_categories walker without links on categories that have subcategories (to make a nested dropdown menu)
- WordPress list categories dropdown with parent-child relation and child under it’s parent
- List a maximum of ‘x’ product categories with qty of ‘y’ in each column
- Searching for a category returns nothing if category is empty
- function query_posts disabling current_page_menu class
- Show different menu on each woocommerce category page
- Theme for subcategories
- Same menu for different taxonomies to reach different content
- Multiple categories for one menu item?
- How to get category id’s which are added in main menu?
- How to Sync Menu, Widgets and other masters from Main Website to its Sub Site
- Link from navbar to categories
- How to get selected taxonomy or category ID if using custom walker?
- Pagination doesn’t work on multiple categories
- Theme modification for custom category menus
- Change appearance based on category but post is in two main categories
- Check is category parent with ids from the childs – get_term_children
- wp_nav_menu not appearing correctly on category page
- wp_list_pages() not showing on posts
- Is custom menu name and category name linked in wordpress?
- Custom menu with categories and tags
- Global navigation in multisite: problem with categories
- How to automatically generate custom menu item from categories?
- wp_dropdown_categories() show elements checkbox
- WP-CLI Add category as menu item main-menu
- Categories are not available AT ALL under Menus
- How to show only the last two categories in a menu?
- ADD DYNAMIC attribute for category to accordion
- How to add all subcategories as submenu in WordPress menu
- Display menu in category and sub category
- WordPress category title not update in navigation menu
- Function add class to second menu specific items if the page has a certain category
- Dynamically display sub-categories on primary menu without adding them
- Show alternative menu based on page template AND post category
- Menu with category 2 category combined
- omit categories from main navigation menu
- How to get the term id inside the start lvl method of category walker?
- Tag Menu items based on their categories
- Backend – Categories and Menus conflicts
- Hide category links if there is nothing in the categories – Main Navigation submenu item
- Using categories and pages in menus
- Category menu that filters out empty categories
- Conditions for single post
- Automatic menu creation for pages with categories?
- How can I add a Categories page link to a menu? [closed]
- Right way for setting categories
- Make three menus with three category levels
- Remove the current item from a menu
- How to prevent uppercasing of menu titles
- Update wordpress menu with woocommerce products
- get_category_children/ the new get_term_children not work