show only a given level in nav menu

You need to extend Walker_Nav_Menu in such a way that it only outputs, if I understand you, items that are not “zero” depth– top level. class my_extended_walker extends Walker_Nav_Menu { function start_lvl(&$output, $depth, $args ) { if (0 !== $depth) { parent::start_lvl($output, $depth, $args); } } function end_lvl(&$output, $depth, $args) { if (0 !== $depth) … Read more

rename navigation menu label in wordpress theme by code

Maybe try filtering just the menu items you want when they get printed back on the front end. You can do that in functions.php Here you can filter the HTML list content for navigation menus. https://developer.wordpress.org/reference/hooks/wp_nav_menu_items/ After some talk, give this a try and then call your lo() where you need it: function lo() { … Read more

Get parent page/menu id of current post

I believe you want get_queried_object. If you have set your static front page and blog page from wp-admin->Settings->Reading then get_queried_object will give you information about the page you chose rather than about the posts in the Loop. Be aware that get_queried_object will return very different types of information depending on the kind of page you … Read more

Hide pages depending on role

To get the current role of the user $current_user = wp_get_current_user(); if ( !($current_user instanceof WP_User) ) return; $roles = $current_user->roles; //$roles is an array After getting role set page ids which you want to show according to roles (for example) if($roles==’administrator’){ $args=array(’21’,’22’,’23’); } or if($roles==’subscriber’){ $args=array(’24’,’25’,’26’); } you can use parse_query filter hook to … Read more

insert element inside wp menu list item

You could use a custom walker or just filter the menu title. It depends on the position you need for your extra content: Should it appear before or inside the link? Example with a walker Update: Actually, this cannot work: the parent function creates the <li, so you have to copy and adjust the whole … Read more

Bar separated navigation by extending Walker_Page

This is what I went with in the end. Although it only will work correctly if you are using a depth of one: class Bar_List_Walker_Page extends Walker_Page { public $count; public $running_count; function __construct() { $this->count = 0; $this->running_count = 0; } function start_el(&$output, $page, $depth, $args, $current_page) { global $post; extract($args, EXTR_SKIP); $css_class = … Read more

Nav menu items disappearing (but not immediately)

Log queries As the question says “it doesn’t happen always”, it’s hard to tell what’s really going on. When you can’t see what happens (query in background) and don’t know when it happens, then it’s best to log it. The logger On activation, the plugin will try to create a log directory named ‘nav_log’ in … Read more