sub menu link is not working

This Code worked for me while ( odrin_have_rows(‘read_the_book_chapters’, $post_id) ) : the_row(); if (odrin_get_sub_field(‘sub’)){ $output .= ‘<li><ul>’; } $output .= ‘<li><a href=”#item’. $item_num = 1 . ‘”>’ . odrin_get_sub_field(‘title’, $post_id) .'</a></li>’;if (odrin_get_sub_field(‘sub’)){ $output .= ‘</ul></li>’;}$item_num++; endwhile; I was missing <li> of sub menu. Meaning that <ul> of sub menu should be within <li> of parent. … Read more

Show some menu sub items as dropdown under a menu item

Remove the first closing </li> and wrap the sub-items inside <ul></ul>, then close the parent <li>. For Example: function my_custom_menu_item($items, $args) { if(is_user_logged_in() && $args->theme_location == ‘primary’) { $user=wp_get_current_user(); $name=$user->display_name; $items .= ‘<li><a href=””>’.$name.'</a>’; $items .= ‘<ul>’; $items .= ‘<li><a href=”http://wordpress.stackexchange.com/my-profile”>My Profile</a></li>’; $items .= ‘<li><a href=”http://wordpress.stackexchange.com/my-posts”>My Posts</a></li>’; $items .= ‘<ul>’; $items .= ‘</li>’; } return … Read more

Displaying Nav Menu

Yes, wp_nav_menu displays all levels of menu by default. You don’t have to write your custom walker class to display submenu items – WordPress already has one which is used by default. WP_Bootstrap_Navwalker is used only because given theme uses Bootstrap and nav menu should generate custom HTML code, which is compatible with Bootstrap. The … Read more

Setting color of specific menu items depending on page or post tag

OK, got it 🙂 add_filter( ‘wp_nav_menu_objects’, ‘add_nav_menu_item_class’ ); function add_nav_menu_item_class( $items ) { foreach ( $items as $item ) { $post_id = get_post_meta( $item->ID, ‘_menu_item_object_id’, true ); $post_tags = get_the_tags( $post_id ); if ( $post_tags ) { foreach( $post_tags as $tag ) { if ( $tag->name == ‘unwatched’ ) { $item->classes[] = ‘unwatched’; } } … Read more

Add value to new attribute inside WordPress menu items

I already had this need, I found this code somewhere in the web. up to you to customize it with your needs. I tested it on the Twenty Nineteen theme: Put this in functions.php : class themeslug_walker_nav_menu extends Walker_Nav_Menu { // add classes to ul sub-menus function start_lvl(&$output, $depth) { // depth dependent classes $indent … Read more

rearrange the posts by published date in Menu posts selection

add_action( ‘pre_get_posts’, ‘AS_order_posts_in_menu_admin’ ); function AS_order_posts_in_menu_admin( $q ) { global $pagenow; if(‘nav-menus.php’ !=$pagenow) return $q; if(isset($q->query_vars[‘post_type’]) && $q->query_vars[‘post_type’]== ‘post’){ $q->query_vars[‘orderby’] = ‘date’; $q->query_vars[‘order’] = “DESC”; } return $q; }