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

How to create a custom menu item

This is the slimmed down version of a plugin settings page that I’m working on. Put it in a file and include it in your plugin. Searching on Google for add_options_page, register_setting, add_settings_field etc. will lead you to the codex entries of WordPress with further descriptions. The code of the options page below will render … Read more

How to change menu according to the language?

This can be done via cookies. We set it with Javascript, reload the page and display different menus in PHP using its value. First, print the script at the site footer (see comments). Note: would be better to enqueue this together with your theme scripts. add_action( ‘wp_footer’, ‘wpse_77220_language_cookie’ ); /** * Cookie script based on … Read more