How do I add a custom sublevel menu specified in one directory to a custom top level menu specified in another directory?

It sounds as if you’re having problems adding submenus from a plugin to a parent item registered in another plugin. Add priorities to your admin_menu actions to make sure the parent(top level) item exists at the point your additional plugins attempt to add items to that menu.. Add top level add_action(‘admin_menu’, ‘main_menu’, 100 ); Add … Read more

How to remove class attributes from custom menu markup?

You can use the nav_menu_css_class filter to remove the classes that you want from your menu-item. See the example below, to remove ALL the CSS classes that are appended to you menu items: add_filter(‘nav_menu_css_class’,’remove_nav_menu_classes’); function remove_nav_menu_classes($classes) { return array(); } Do a print_r($classes) if you want to know which classes are active in your menu.

Second menu not showing

You need to pass an array of menus to the register_nav_menu function like so: register_nav_menus( array( ‘menu-1’ => ‘Menu Top’, ‘menu-2’ => ‘Menu Bottom’ ) ); You then call them in your theme: <?php wp_nav_menu( array( ‘theme_location’ => ‘menu-2’ ) ); ?>

WordPress cache a menu with Transient API

wp_nav_menu() doesn’t return anything by default, it just echoes out formatted html. For wp_nav_menu() to return a value you will need to pass ‘echo’ => false into it’s arguments, like so: $housemenu = wp_nav_menu( array( ‘menu’ => ”, ‘menu_class’ => ‘sf-menu’, ‘menu_id’ => ‘nav’, ‘walker’ => new description_walker(), ‘echo’ => ‘false’ )); It should be … Read more

list pages only from master parent

This is what I have used in a few projects that always displays the children pages even if you’re are viewing a child page. See if this is what you had in mind <?php if(!$post->post_parent){ // will display the subpages of this top level page $children = wp_list_pages(“title_li=&child_of=”.$post->ID.”&echo=0″); $ancestors = $post->ID; }else{ // diplays only … Read more

Appearance -> Menu -> Menu Structure : Add plain HTML code as an element

You can add your flag (plain) html into menu at last li tag. <?php function add_last_nav_item($items, $args) { if ($args->menu->slug == ‘topbar-menu’) { // change your menu slug name // Add your html $item = ‘<li class=”searchbox”> <input type=”search” placeholder=”Search……” name=”search” class=”searchbox-input” onkeyup=”buttonUp();” required> <input type=”submit” class=”searchbox-submit” value=””> <span class=”searchbox-icon”><i class=”fa fa-search”></i></span> </li>’; $items = … Read more

Making menu link open in new tab?

You can do that with jQuery. We can open this link in new tab/window by adding target=”_blank” attribute dynamically on link which has URL https://www.example.com. Here is the example function for that. function wpse_my_custom_script() { ?> <script type=”text/javascript”> jQuery(document).ready( function($) { $( “ul#adminmenu a[href$=’https://www.example.com’]” ).attr( ‘target’, ‘_blank’ ); }); </script> <?php } add_action( ‘admin_head’, ‘wpse_my_custom_script’ … Read more

How can I get the page url slug when ‘post_name’ returns an id?

Try this : $menu = get_term( $locations[$theme_location], ‘nav_menu’ ); $menu_items = wp_get_nav_menu_items($menu->term_id); foreach( $menu_items as $menu_item ) { $link = $menu_item->url; $title = $menu_item->title; $slug = basename($menu_item->url); } Pass the whole permalink to the basename function, which will automatically process the URL and give us only the slug.