Making breadcrumb with wp_nav_menu

I couldn’t believe there is not a single FREE plugin available that does this. So I wrote my own function. Here you go. Just copy this to your functions.php: function my_breadcrumb($theme_location = ‘main’, $separator=” > “) { $theme_locations = get_nav_menu_locations(); if( ! isset( $theme_locations[ $theme_location ] ) ) { return ”; } $items = wp_get_nav_menu_items( … Read more

how to create a menu with all sub categories?

This depends on what kind of menu you are talking about: 1) If you are talking about “custom menus” (found in the Backend under Design -> Menus) you can do the following: Create a new function with the action hook add_category inside of this function, you can create a new post of type the menu … Read more

How do I add support to my theme for custom menus?

The easiest way is to use the register_nav_menus function.This should be hooked into ‘after_setup_theme’: function my_cool_menu_function(){ register_nav_menus( array( ‘primary’ => ‘Primary Navigation’ )); } add_action( ‘after_setup_theme’, ‘my_cool_menu_function’ ); Then, in your theme, simply call that menu’s position: wp_nav_menu( array( ‘theme_location’ => ‘primary’ ) );

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.