Adding category ID or slug to WP Nav Menu

Use the nav_menu_css_class filter to add classes to wp_nav_menu output. Add ID (no additional query needed): function wpa_category_nav_class( $classes, $item ){ if( ‘category’ == $item->object ){ $classes[] = ‘menu-category-‘ . $item->object_id; } return $classes; } add_filter( ‘nav_menu_css_class’, ‘wpa_category_nav_class’, 10, 2 ); Add slug (loads category object via get_category): function wpa_category_nav_class( $classes, $item ){ if( ‘category’ … Read more

Adding line breaks to nav menu items

Following the hint from @Rarst regarding safe characters here’s what I ended up doing: function wpa_105883_menu_title_markup( $title, $id ){ if ( is_nav_menu_item ( $id ) && ! is_admin() ){ $title = preg_replace( ‘/#BR#/’, ‘<br/>’, $title ); } return $title; } add_filter( ‘the_title’, ‘wpa_105883_menu_title_markup’, 10, 2 ); Edit: Also per Rarst’s comment I’ve replaced the preg_replace … Read more

WordPress Settings API, Implementing Tabs On Custom Menu Page

Here is how I do it, beware, post is extensive. /* Add Menus —————————————————————–*/ add_action(‘admin_menu’, ‘ch_essentials_admin’); function ch_essentials_admin() { /* Base Menu */ add_menu_page( ‘Essentials Theme’, ‘Essentials Theme’, ‘manage_options’, ‘ch-essentials-options’, ‘ch_essentials_index’); } Now for my settings fields, extra fields removed, just as an example. This is for ‘Front Page Settings’ and ‘Front Page Tab’ add_action(‘admin_init’, … Read more

remove “edit your profile” from admin menu bar

There is a remove_menu hook for the admin menu bar. The class you want to hook into $wp_admin_bar , you can see the remove function here and test it out since there is no documentation on it ( line 86), it should work with the submenu ID. http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/class-wp-admin-bar.php Since you did not seem to believe … Read more

How do I programatically insert a new menu item?

Before being printed, all the menu items get run through a filter. You can target the wp_nav_menu_items filter to tack things on to the menu: // Filter wp_nav_menu() to add additional links and other output function new_nav_menu_items($items) { $homelink = ‘<li class=”home”><a href=”‘ . home_url( “https://wordpress.stackexchange.com/” ) . ‘”>’ . __(‘Home’) . ‘</a></li>’; // add … Read more

How to modify navigation menu of the “My Account” page in WooCommerce

For that, you do not need to modify the woocommerce/templates/myaccount/navigation.php. The best way to customize the “My Account” navigation menu items is to use: woocommerce_account_menu_items filter hook to add new items to the menu. array_slice() to reorder them the way you want. This way, by using woocommerce_account_menu_items filter hook, you integrate perfectly your own items … Read more

How to add custom post type archive page links to nav menu?

This is one method that I think should work (though it’s not tested). //Hook on to the filter for the (custom) main menu // ‘wp_list_pages’ filter is a fallback, when a custom menu isn’t being used add_filter( ‘wp_list_pages’, ‘new_nav_menu_items’ ); add_filter( ‘wp_nav_menu_items’, ‘new_nav_menu_items’ ); //Can also hook into a specific menu… //add_filter( ‘wp_nav_menu_{$menu->slug}_items’, ‘new_nav_menu_items’ ); … Read more

Filter wp_nav_menu()

I think I got the answer: function my_nav_menu( $args = array() ) { $echo = isset( $args[‘echo’] ) ? (bool)( $args[‘echo’] ) : true; $args[‘echo’] = false; add_filter( ‘wp_nav_menu_objects’ , ‘my_filter_nav_menu’ , 100 , 2 ); $menu = wp_nav_menu( $args ); remove_filter( ‘wp_nav_menu_objects’ , ‘my_filter_nav_menu’ , 100, 2 ); if( $echo ) echo $menu; else … Read more