Custom Post Type & Custom Menu Walker to append custom class for active post types

When i want to add the classes current-menu-item and current-page-ancestor i always use the wp_nav_menu without any custom walker. I only build my own walker if i want to change lets say the classes to something like “sel” instead. So i add the menu like this: <?php wp_nav_menu( array( ‘theme_location’ => ‘company-menu’, ‘container’ => false, … Read more

wordpress add_submenu_page adds broken link

WordPress is doing exactly what you’re telling it to do. Refer to the Codex entry for add_submenu_page(). The functions arguments are like so: <?php add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function ); ?> So, you’re assigning the same string to $parent_slug and $menu_slug. For obvious reasons, these two need to be different. $parent_slug is the … Read more

remove class “sub-menu” from wordpress drop down menu

For anybody interested in the code to remove any class you want. I Just worked with the Roots theme and they did the replacement like below. You can just add the class you want to replace in the list. /** * Replace various active menu class names with “active” or nothing * */ function roots_wp_nav_menu($text) … Read more

Add span in top menu item with nested itens

You can use the walker_nav_menu_start_el filter: add_filter( ‘walker_nav_menu_start_el’, ‘wpse_add_arrow’,10,4); function wpse_add_arrow( $item_output, $item, $depth, $args ){ //Only add class to ‘top level’ items on the ‘primary’ menu. if(‘primary’ == $args->theme_location && $depth ==0){ $item_output .='<span class=”arrow”></span>’; } return $item_output; } This assumes that you’re using wp_nav_menu( array( ‘theme_location’ => ‘primary’) ); to display the menu. … Read more

Insert a div before the wp_nav_menu

How do I go about inserting a custom div before the wp_nav_menu() adds the ul? That’s what the ‘container’ array key defines: the element that contains the menu. The menu will always output as a <ul>, wrapped in a container of the type specified by the ‘container’ array key: either a <div> (default), by passing … Read more

Give child-categories same class (the parent category-slug) as parent in menu list?

If you want only 2 levels, you may use the parent parameter. Example <?php $args = array( ‘hide_empty’ => 0, ‘parent’ => 0 ); $categories = get_categories($args); $menu = ‘<ul class=”nav”>’; // iterate through your categories foreach($categories as $category) { $menu .= ‘<li class=”‘ . ‘cat-item category-‘ . $category->slug . ‘”>’ . ‘<a href=”‘.get_category_link($category->term_id ).'” … Read more