Default Nav Highlight

Assuming you are loading a single piece of content like one Post (unlike the homepage where you’re combining multiple Pages with JS), something like this should do it: <script type=”text/javascript”> $(document).ready(function(){ // get each menu item var hasHighlight = 0; // loop through to see if any have “current_page_item” class $(“#nav ul li”).each(function(obj) { if($(this).hasClass(“current_page_item”)) … Read more

How can i make multilevel menu in wordpress theme with bootstrap

Download Bootstrap nav walker file.Call this file to your functions.php. Then Put this code to dynamic your nav menu: <?php $args = array( ‘theme_location’ => ‘primary’, ‘menu’ => ‘Main’, ‘container’ => ‘false’, ‘container_class’ => ”, ‘container_id’ => ”, ‘menu_class’ => ‘nav navbar-nav navbar-right’, ‘menu_id’ => ”, ‘echo’ => true, ‘fallback_cb’ => ‘wp_page_menu’, ‘before’ => ”, … Read more

How can I create a new menu item that links to an archive of a custom post type?

After searching through the core WordPress files, I found the necessary arguments. The key is setting menu-item-object to be the slug of your post type and the menu-item-type to be post_type_archive. $args = [ ‘menu-item-position’ => $position, ‘menu-item-status’ => ‘publish’, ‘menu-item-parent-id’ => 0, ‘menu-item-object’ => ‘my-post-type’, ‘menu-item-type’ => ‘post_type_archive’ ]; wp_update_nav_menu_item($menuID, 0, $args);

wp_nav_menu: Is there a way to modify the output of that got a submenu?

You should be able to use nav_menu_link_attributes to add attributes to links output by wp_nav_menu that have child/submenu links. wp_nav_menu conditionally assigns classes to links it outputs. You need to target links with the class .menu-item-has-children You can add the attributes you want with the following filter/function: add_filter( ‘nav_menu_link_attributes’, ‘wpse270596_add_navlink_atts’, 10, 3 ); function wpse270596_add_navlink_atts( … Read more

Get the name of menu item with wp_nav_menu

The object_id holds the ID of whatever object the menu item refers to, this will be a post, post etc. The get_queried_object_id() will give you the ID of the current page. $menu_items = wp_get_nav_menu_items( ‘main-menu’ ); $this_item = current( wp_filter_object_list( $menu_items, array( ‘object_id’ => get_queried_object_id() ) ) ); echo $this_item->title;

Searching for a category returns nothing if category is empty

You can modify this behaviour by adding a custom filter to your functions.php or as a plugin: add_filter(‘get_terms_args’, ‘wodruoso_terms_args’, 10, 1); function wodruoso_terms_args($args) { /* note: I am checking here that we are in WP Admin area and that it’s * search by category name to minimize impact on other areas */ if(is_admin() && isset($args[“name__like”]) … Read more

How to add Plugin functionality in WordPress Frontend Menus

At the time of registering taxonomy, make sure you use the show_in_nav_menus parameter and set it true. For Example: $args = array( ‘label’ => __( ‘book’, ‘textdomain’ ), ‘public’ => true, ‘rewrite’ => array(‘slug’ => ‘book’, ‘with_front’ => true), ‘hierarchical’ => true, ‘show_in_nav_menus’ => true, ‘show_ui’ => true, ); register_taxonomy( ‘book’, ‘products’, $args);