wp_nav_menu – page template name as item class

The nav_menu_css_class filter will let you add CSS classes to specific menu items. We combine that with the get_page_template_slug function to fetch the page template filename, then we use that with the get_page_templates method of the theme class to get the template name as defined in the Template Name: header. Then we pass that result … Read more

Add static item to wp_nav_menu

The reason your PRODUCTS menu is appearing first is because you’re echoing it out to the page as part of the filter function. The expectation with filters is that your function receives an argument, $items in this case, modifies it and then returns it to be used by the core code. In order to avoid … Read more

jQuery cookie not working properly in wordpress

Ok, I solve this with the help of @TheDeadMedic’s help. I use wordpress cookiepath constant and it works on wordpress perfectly. Here is the jquery code: jQuery(document).ready(function () { // baking cookie ;p function set_cookie(ID) { document.cookie = ID + “=opened; path=<?php echo COOKIEPATH ?>”; } // getting it out from the oven… function get_cookies_array() … Read more

Add sidebars to navigation menu?

might it can help you for your query : Basically I need a way to display widgets in menu, without using any extra plugins. place the code in your theme’s functions.php <?php register_sidebar( array( ‘name’ => ‘Page Menu’, ‘id’ => ‘page-menu’, ‘before_widget’ => ‘<div id=”page-nav”>’, ‘after_widget’ => ‘</div>’, ‘before_title’ => false, ‘after_title’ => false ) … Read more

Does the menu item ID ever change?

WordPress menus are their own Post Type ( nav_menu_item ). Every time you add a new item to a menu it create a new “post” in the nav_menu_item post type and assigns it a new ID just as deleting and recreating a page removes / adds new ids. This means the only way the Navigation … Read more

How can I put two menus in the same div?

Try setting ‘container’ => false, in the wp_nav_menu() options array and using your own HTML to wrap the output. <div class=”outer-container-whatever-bootstrap-classes”> <nav class=”navbar-left other-classes”> <?php wp_nav_menu( array( [your_options with ‘container’ => false,] ) )’ ?> </nav> <nav class=”navbar-right other-classes”> <?php wp_nav_menu( array( [your_options with ‘container’ => false,] ) )’ ?> </nav> </div>

Programmatically adding menu items function replicates in multiple menus

You can use the second input argument $args to target the specific menu. Here’s an example with some checks that you can adjust to your needs: add_filter( ‘wp_nav_menu_objects’, function( $sorted_menu_items, $args ) { if( ‘primary’ === $args->theme_location // Alternative && ‘some_menu_slug’ === $args->menu->slug // Alternative ) { // Your stuff here … } return $sorted_menu_items; … Read more