Return only top-level navigation items from a menu using wp_get_nav_menu_items

Let’s take a look at wp_get_nav_menu_items code reference. It takes two parameters: $menu – (int|string|WP_Term) (Required) Menu ID, slug, name, or object, $args – (array) (Optional) Arguments to pass to get_posts(). So we can use get_posts args in here… And if we want to get only top-level posts, then post_parent arg comes useful… So something … Read more

HTML Bootstrap navigation menu to WordPress menu using wp_nav_menu

You have to edit the files in: wordpress/wp-content/themes/twentyseventeen/template-parts/navigation/navigation-top.php and then create a custom walker, try to take a look here. Try in this way: <?php /** * Displays top navigation * * @package WordPress * @subpackage Twenty_Seventeen * @since 1.0 * @version 1.2 */ ?> <div class=”container”> <nav class=”navbar navbar-expand-lg navbar-light” id=”mainNav”> <a class=”navbar-brand js-scroll-trigger” … Read more

How can I show different menu for different pages?

You can try it this way. Now we are talking about pages you can set up a separate template for the page that needs a different menu. This where WordPress’s newer menu feature is really nice. First if you are using the newer menu feature of WordPress place this in place of your current menu: … Read more

How is custom menu hierarchy output handled?

Each nav menu item is stored a post type named nav_menu_item. The horizontal position is stored in the column menu_order The vertical position (hierarchy) is stored as post meta field named _menu_item_menu_item_parent holding the parent nav_menu_item ID. To create nested lists WordPress looks for _menu_item_menu_item_parent on each item, and if there is an item with … Read more

wp_nav_menu() loses ‘current-menu-*’ classes on single product page within category

Looking for a solution for the same problem, I came across this: add_filter( ‘nav_menu_css_class’, ‘add_parent_url_menu_class’, 10, 2 ); function add_parent_url_menu_class( $classes = array(), $item = false ) { // Get current URL $current_url = current_url(); // Get homepage URL $homepage_url = trailingslashit( get_bloginfo( ‘url’ ) ); // Exclude 404 and homepage if( is_404() or $item->url … Read more

Overriding wp_nav_menu default arguments

If you want the options to be extensible by developers, just add a custom filter to the output: wp_nav_menu( apply_filters( ‘wpse119371_nav_menu_args’, array( ‘theme_location’ => ‘primary’, ‘container’ => false, // etc. ) ) ); Then, a developer merely has to add a filter callback: function wpse119371_filter_nav_menu_args( $args ) { // Modify $args $args[‘container’] => ‘div’; // … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)