How to get current-menu-item title as variable?

This is possible by filtering wp_nav_menu_objects, which is the easiest place to check which item is the current menu item, because WordPress already added the classes for you. add_filter( ‘wp_nav_menu_objects’, ‘wpse16243_wp_nav_menu_objects’ ); function wpse16243_wp_nav_menu_objects( $sorted_menu_items ) { foreach ( $sorted_menu_items as $menu_item ) { if ( $menu_item->current ) { $GLOBALS[‘wpse16243_title’] = $menu_item->title; break; } } … Read more

wp_get_nav_menu_items() not working with slug

Since nobody has really explained why the function doesn’t work the way you thought it did, I shall take a stab at explaining it in detail as I just fell for the same trap as you did. This is where the docs aren’t really clear as to what the slug is referring to. Most people … Read more

Add container to nav_menu sub menu

Use a custom walker, extend the methods start_lvl() and end_lvl. Sample code, not tested: class WPSE_78121_Sublevel_Walker extends Walker_Nav_Menu { function start_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat(“\t”, $depth); $output .= “\n$indent<div class=”sub-menu-wrap”><ul class=”sub-menu”>\n”; } function end_lvl( &$output, $depth = 0, $args = array() ) { $indent = str_repeat(“\t”, $depth); … Read more

How can I display a menu on certain pages only?

That’s a nice option, but I agree with sri, right now it really depends on your theme. You can do a work-around through is_page(). You need to write something like this on your page.php theme file: <?php if (is_page(‘projects’)) { if ( is_active_sidebar( ‘sidebar-navigation’ )) { dynamic_sidebar( ‘sidebar-navigation’ ); } } ?> If you want … Read more

Add settings to menu items in the Customizer

You’re running up against an incomplete implementation of modifying nav menus in the Customizer. In particular, inside of the phpdoc for WP_Customize_Nav_Menu_Item_Setting::preview() you can see this comment: // @todo Add get_post_metadata filters for plugins to add their data. Nevertheless, even though we didn’t implemented core support for previewing changes to nav menu item postmeta, it … Read more

Using a menu walker add a custom item at the end of the menu’s items

You don’t need a walker in this case. A filter called wp_nav_menu_items is available. It allows you to edit the list items of a menu. Just append your own list item with search field. add_filter( ‘wp_nav_menu_items’, ‘add_search_to_nav’, 10, 2 ); function add_search_to_nav( $items, $args ) { $items .= ‘<li>SEARCH</li>’; return $items; } Note: if you … Read more

Add a custom walker to a menu created in a widget

If you look at implementation of WP_Nav_Menu_Widget class you will see the following code: function widget($args, $instance) { // Get menu $nav_menu = ! empty( $instance[‘nav_menu’] ) ? wp_get_nav_menu_object( $instance[‘nav_menu’] ) : false; if ( !$nav_menu ) return; $instance[‘title’] = apply_filters( ‘widget_title’, empty( $instance[‘title’] ) ? ” : $instance[‘title’], $instance, $this->id_base ); echo $args[‘before_widget’]; if … Read more

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