add custom class to wp_nav_menu using filter hook nav_menu_css_class

here is a simply example: add_filter(‘nav_menu_css_class’, ‘auto_custom_type_class’, 10, 2 ); function auto_custom_type_class($classes, $item) { if ($item->type_label == “CUSTOM_TYPE_NAME”){ $classes[] = “New_Class”; } return $classes; } just change CUSTOM_TYPE_NAME to the name of your custom post type and New_Class with the name of your class and paste this snippet in your theme’s functions.php file.

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 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

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

Add custom menu item using wp_nav_menu_items filter

I’ve created these two functions you may use to add custom items to a given menu item present in your menu (page, post, link…). In your case, you can add these function to your functions.php and call them like this: $menu_name=”Your Menu Name”; $name_of_menu_item_to_append_to = ‘My Account’; $id_of_menu_item_to_append_to = get_wp_object_id( $name_of_menu_item_to_append_to, ‘nav_menu_item’ ); $new_submenu_item = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)