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

Is there a function to cause empty categories not to show in menus?

add_filter( ‘wp_get_nav_menu_items’, ‘nav_remove_empty_category_menu_item’, 10, 3 ); function nav_remove_empty_category_menu_item ( $items, $menu, $args ) { global $wpdb; $nopost = $wpdb->get_col( “SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE count = 0” ); foreach ( $items as $key => $item ) { if ( ( ‘taxonomy’ == $item->type ) && ( in_array( $item->object_id, $nopost ) ) ) { unset( $items[$key] … 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

Create a select drop down of available menus

It is not intuitive but get_terms will do it, if I understand what you need. var_dump(get_terms( ‘nav_menu’)); If you look in the *_term_taxonomy table you can see why. The menus are stored as a taxonomy named nav_menu. This won’t get you things like page menus, only the intentionally created menus.

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