Check if page is in a certain menu

Here’s the function I wrote to figure this out. You give it a menu slug/name/ID and post/page ID and it returns TRUE if that post/page is in the specified menu and FALSE otherwise. Then it was just simply a matter of a quick if/else statement to check against the two menus and display the correct … Read more

Adding a custom field to the site identity menu

You’ll have to add your own customizer controls to achieve that. So for example, if you want to add Company Name, you can use this code: function my_register_additional_customizer_settings( $wp_customize ) { $wp_customize->add_setting( ‘my_company_name’, array( ‘default’ => ”, ‘type’ => ‘option’, // you can also use ‘theme_mod’ ‘capability’ => ‘edit_theme_options’ ), ); $wp_customize->add_control( new WP_Customize_Control( $wp_customize, … Read more

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