if role is logged in then do something

Something like this would be more efficient. This is basic PHP by the way, not WP specific. function add_extra_item_to_nav_menu( $items, $args ) { $roles = [ ‘administrator’ => [ //Role – slug name ‘SCHOOL_NAME-A’, //url path – appended to the end ‘ADMIN’, // can be any name – appended to SHOP NOW button ], ‘ROLEABC’ … Read more

wp_get_nav_menu_items order doesn’t work

When you look in WordPress source code, you will find reason for that. On line 538 of nav-menu.php you’ll find: if ( ARRAY_A == $args[‘output’] ) { $GLOBALS[‘_menu_item_sort_prop’] = $args[‘output_key’]; usort($items, ‘_sort_nav_menu_items’); $i = 1; foreach( $items as $k => $item ) { $items[$k]->$args[‘output_key’] = $i++; } } I didn’t check why, but it looks … Read more

Replacing a specific menu item

This is relatively easily done using the walker_nav_menu_start_el filter (without all that PHP tag spam): function nav_replace_wpse_189788($item_output, $item) { // var_dump($item_output, $item); if (‘Profile’ == $item->title) { global $my_profile; // no idea what this does? if (is_user_logged_in()) { return ‘<div class=”img” data-key=”profile”>’.get_avatar( get_current_user_id(), 64 ).'</div>’; } } return $item_output; } add_filter(‘walker_nav_menu_start_el’,’nav_replace_wpse_189788′,10,2); Note: I had to … Read more

I want remove last after wp_nav_menu

This will replace the last occurrence of your after string. function replace_last_nav_item($items, $args) { return substr_replace($items, ”, strrpos($items, $args->after), strlen($args->after)); } add_filter(‘wp_nav_menu’,’replace_last_nav_item’,100,2); Pure CSS will do this too: .btn_bar:last-child{display:none}

Adding html elements to wp nav menu

I made a dynamic menu using this code: //add login/logout link to menu add_filter(‘wp_nav_menu_items’, ‘wps_add_login_logout_link’, 10, 2); function wps_add_login_logout_link($items, $args) { $login = __(‘Sign in’); $logout = __(‘Sign out’); $menu_id = ’15’; $menu_id2 = ’16’; if ( ! is_user_logged_in() ) $link = ‘<a href=”‘ . site_url(‘log-in-log-out’) . ‘”>’ . $login . ‘</a>’; else $link = … Read more

Minor css-change based on topmenu – how?

My answer adds a class to the <body> element via the body_class filter. This is probably the easiest way to apply extra formatting to any element on the page. The added classes are wpse14430_products, wpse14430_services or wpse14430_contact (based on the slugs of the top pages in your example). Using wp_nav_menu() If you use wp_nav_menu() to … Read more

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