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

wp_delete_auto_drafts() deletes links in menus

This is what normal query run by wp_get_associated_nav_menu_items() looks like: SELECT wp_posts.* FROM wp_posts INNER JOIN wp_postmeta ON ( wp_posts.id = wp_postmeta.post_id ) WHERE 1 = 1 AND wp_posts.post_type=”nav_menu_item” AND (( wp_posts.post_status <> ‘trash’ AND wp_posts.post_status <> ‘auto-draft’ )) AND (( wp_postmeta.meta_key = ‘_menu_item_object_id’ AND Cast(wp_postmeta.meta_value AS CHAR) = ‘3111’ )) GROUP BY wp_posts.id ORDER … 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

Now can I group custom post types together?

If you are wondering how to group multiple post types under one menu, you can easily do this with the show_in_menu argument when setting up your menu. See below: $args = array( ‘public’ => true, ‘show_ui’ => true, ‘query_var’ => true, ‘rewrite’ => true, ‘capability_type’ => ‘post’, ‘hierarchical’ => false, ‘show_in_menu’ => ‘your-custom-menu-slug.php’, ‘menu_position’ => … Read more

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

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