Highlight parent menu item when child is not in menu

Alrdy got it: <?php //in functions.php add_filter(‘nav_menu_css_class’, ‘highlight_portfolio’, 12, 2); function highlight_portfolio($classes, $item) { $parent = get_post_ancestors(); $parent_ID = $parent[0]; if ($parent_ID == $item->object_id) { array_push($classes, ‘current-menu-ancestor’); } return $classes; }

Menu limit, cannot add new menu items

I had a similar issue with a client’s server, and the solution in their case was to increase the php max_input_vars setting in php.ini. The number of menu items times the number of attributes for each item was exhausting the allowed input vars, so the server was silently truncating the request, resulting in menu items … Read more

Remove unusable metaboxes in nav menu management screen

There are two important global variables in wp-admin/nav-menus.php: $nav_menus is an array of all available menus, filled with wp_get_nav_menus(). $wp_meta_boxes[‘nav-menus’] is an array of all available metaboxes for this screen. We can hook into admin_head-nav-menus.php, an action called after the first variable has been set up, and change the second variable: add_action( ‘admin_head-nav-menus.php’, ‘t5_hide_dead_menu_metaboxes’ ); … Read more

Using nonce in menu item

Just add a filter: function change_menu($items){ foreach($items as $item){ if( $item->title == “Log Out”){ $item->url = $item->url . “&_wpnonce=” . wp_create_nonce( ‘log-out’ ); } } return $items; } add_filter(‘wp_nav_menu_objects’, ‘change_menu’);

Whats the difference between current_page_item and current-menu-item

current_menu_item is the active element in the menu, independent from the type (page, archives, post, etc.) of the current menu element, while current_page_item only available, if the current item is a page and is current. For more details: http://codex.wordpress.org/Dynamic_Menu_Highlighting

Renaming a WordPress Admin Menu

This is what I do to rename menu items: in the action hook admin_menu, use a recursive array search to pinpoint the key position of the desired menu and then modify the global $menu array. add_action( ‘admin_menu’, ‘rename_woocoomerce_wpse_100758’, 999 ); function rename_woocoomerce_wpse_100758() { global $menu; // Pinpoint menu item $woo = recursive_array_search_php_91365( ‘WooCommerce’, $menu ); … Read more

How to change order of menu items

Go to appearance -> menus section. Here you can create menus, add menu items and drag them around to place it to your desired place. Alternatively, you can set up the menu order of a page. Just click edit page and you will see the menu order it should be under Page attribute section.

Removing link ” from ” menu for some “links” without JS

Assuming you’re using wp_nav_menu() to display your navigation you could apply a walker that looks for css classes: $items_wrap = ‘<nav class=”…”>’; $items_wrap .= ‘<ul id=”%1$s” class=”%2$s”>%3$s</ul>’; $items_wrap .= ‘</nav>’; wp_nav_menu( array( ‘container’ => false, ‘container_class’ => false, ‘menu_class’ => ‘…’, ‘echo’ => true, ‘before’ => ”, ‘after’ => ”, ‘link_before’ => ”, ‘link_after’ => … Read more

How to create this custom menu walker?

You need to set-up your own menu walker (link to WordPress Codex), and in there add custom start_el and end_el overrides. So for example your start_el and end_el may look something like this: function start_el(&$output, $item, $depth=0, $args=array()) { $output .= “<div>” . esc_attr($item->label); } function end_el(&$output, $item, $depth=0, $args=array()) { $output .= “</div>\n”; } … Read more

Increase search results for Admin -> Appearance -> Menus -> Search (default is 10)

No need to change core files! Here is a hook (add in functions.php or simple plugin): // filtering quick-menu-search results (this seems better than others at https://pastebin.com/raw/jRkJYAzE ) add_action( ‘pre_get_posts’, ‘myFilter1’, 10, 2 ); function myFilter1( $q ) { // example of $q properties: https://pastebin.com/raw/YK1uaE0M if(isset($_POST[‘action’]) && $_POST[‘action’]==”menu-quick-search” && isset($_POST[‘menu-settings-column-nonce’])){ // other parameters for more … Read more

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