WordPress Shortcode in Menu Item Title

First of all download ‘Shortcodes in Menus’ plugin and install/activate it. Then in theme’s function.php add following code. add_shortcode( ‘current-username’ , ‘ss_get_current_username’ ); function ss_get_current_username(){ $user = wp_get_current_user(); return $user->display_name; } Now, in menu’s navigation lable write [current-username] shortcode. Same thing you can do for displaying avatar. This way it will display logged in user … Read more

fall back for main menu?

The parameter fallback_cb will be used when the user has no menu assigned to your theme_location. It should be a function that returns a string, but you can use __return_false() to suppress any output: wp_nav_menu( array( ‘theme_location’ => ‘primary’, // No menu available: no output. ‘fallback_cb’ => ‘__return_false’ ) ); You should always declare the … Read more

How does a minimal menu walker look like?

You could create a very simple walker, like this one. To detect the current item, inspect $item->current. It is TRUE for the current item only. I wouldn’t add a class, but deactivate the useless link completely, because it doesn’t have to be clickable anyway. Example: class One_Line_Walker extends Walker { public function walk( $elements, $max_depth … Read more

Unregister Nav Menu from Child-Theme

The Starkers theme setup is hooked to after_setup_theme, at a priority of 10. So you basically have to wrap the unregister function inside another function (child themes functions.php file) and add it later than the parent themes setup function, so it gets first added by the parent and later on removed by the child. function … Read more

Custom search filter causes menu and query_posts problems

Use is_main_query() to modify only the main query so menu will stay not affected. Try This: add_action( ‘pre_get_posts’, ‘fteh_pre_get_posts’ ); function fteh_pre_get_posts( $query ){ if( !is_admin() && $query->is_main_query() && isset( $query->query_vars[‘type’] ) ) $types = explode( ‘,’, $query->query_vars[‘type’] ); $query->set( ‘post_type’, $types ); return $query; }

wp_nav_menu remove class and id from li

If you look in the wp_nav_menu() function, you see the items are written by walk_nav_menu_tree(), which calls Walker_Nav_Menu to do the work (unless you specified your own walker class). This class contains a method start_el() that is called for each menu item. In this function, you see that the classes are filtered through nav_menu_css_class and … Read more

How to limit wordpress menu depth in admin panel

Follow up on @jmarceli’s and @squarecandy’s great answers. Here is a solution that allows for: Easier scaling (set an object in the php action) Updates to the correct menu depth when the location checkboxes are changed /** * Limit max menu depth in admin panel */ function limit_admin_menu_depth($hook) { if ($hook != ‘nav-menus.php’) return; wp_register_script(‘limit-admin-menu-depth’, … Read more

Menu Items Disappearing

The following has worked for some users with similar problem: Try to increase the value of the max_input_vars variable in php.ini. This variable was introduced in PHP version 5.3.9 and has the default value of 1000. You can read more about it in the PHP documentation: http://php.net/manual/en/info.configuration.php max_input_vars 1000 PHP_INI_PERDIR Available since PHP 5.3.9. How … Read more