Add data-track to links in menu

So there’s actually a filter for this, provided your theme doesn’t use its own menu walker class: function add_data_track_attribute( $atts, $item, $args ) { $title = apply_filters( ‘the_title’, $item->title, $item->ID ); // $title = sanitize_title($title); // if you need a slug-like title $atts[‘data-track’] = ‘navigation|click|’.$title; return $atts; } add_filter(‘nav_menu_link_attributes’, ‘add_data_track_attribute’, 10, 3); Note the commented-out … Read more

Current Post Parent Category & Child Category Links

Display the categories (or terms from other taxonomies) assigned to a post ordered by parent-child category relationship. Similar to the function get_the_category_list() which orders the categories by name. This example must be used inside the loop. <?php $taxonomy = ‘category’; // Get the term IDs assigned to post. $post_terms = wp_get_object_terms( $post->ID, $taxonomy, array( ‘fields’ … Read more

wp_nav_menu doesn’t seem to work on custom post type pages

You can just add these parameters in array variable and pass this to wp_nav_menu() Like: function get_menu_params(){ $defaults = array( ‘menu’ => ‘Primary Menu’, ‘theme_location’ => ‘primary’, ‘depth’ => 3, ‘container’ => ‘div’, ‘container_class’ => ‘a’, ‘container_id’ => ‘b’, ‘menu_class’ => ‘nav navbar-nav’, ‘fallback_cb’ => ‘wp_bootstrap_navwalker::fallback’, ‘walker’ => new wp_bootstrap_navwalker() ); return $defaults; } and … Read more