Show navigation header menu by post and categery

This code will check to ensure that the theme_location is header. Also, menu is the parameter where the desired WordPress Nav menu is specified. menu_id is the HTML ID that is applied to the <ul> element which forms the menu. Docs on the arguments for wp_nav_menu() can be found here. add_filter( ‘wp_nav_menu_args’, ‘bb_wp_nav_menu_args’ ); function … Read more

Navigate to external link if last page or post in a category

Since it’s not clear exactly what you need it’s hard to give you the best solution. However … You should be able to use get_next_posts_link() in your loop template. Or get_previous_posts_link() if that’s what you want. If that returns null you can then echo a link to whereever you want in your template. if(!get_next_posts_link()) { … Read more

index.php navigation

I think you should use wp_link_pages function, it’s was built for that purpose. $defaults = array( ‘before’ => ‘<p>’ . __( ‘Pages:’ ), ‘after’ => ‘</p>’, ‘link_before’ => ”, ‘link_after’ => ”, ‘next_or_number’ => ‘number’, ‘separator’ => ‘ ‘, ‘nextpagelink’ => __( ‘Next page’ ), ‘previouspagelink’ => __( ‘Previous page’ ), ‘pagelink’ => ‘%’, ‘echo’ … Read more

Can the_post_navigation() be outside of the loop?

Yes, the_post_navigation() works outside of the loop on single post views. Following the function calls, the_post_navigation() uses get_the_post_navigation() which uses get_previous_post_link() and get_next_post_link() which use get_adjacent_post_link() which finally uses get_post() which defaults to the global $post object. Here’s an excerpt of get_adjacent_post_link(): function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms=””, $previous = true, $taxonomy = … Read more

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