How to var_dump nav menu items from anywhere?

The items are set up in wp_nav_menu(). There is a useful filter you can use: ‘wp_nav_menu_objects’. It offers the items as $sorted_menu_items and the arguments of the wp_nav_menu() call as $args. From wp-includes/nav-menu-template.php::wp_nav_menu(): $sorted_menu_items = apply_filters( ‘wp_nav_menu_objects’, $sorted_menu_items, $args ); So … hook into this filter, store the data somewhere, return the $sorted_menu_items unchanged and … Read more

Menu items id’s – are they 100% unique?

Yes it is always unique. id 814 cant be applied again unless you update it manually on your DB. Its because of auto increment .. DB automatically increment id so everytime next id will be +1 814 815 816 and so on.. Even if you delete an id in between. It wont affect auto incrementation. … Read more

How to register custom menu widget

Try this code (in function.php) class MyWidget extends WP_Widget { function __construct() { $widget_ops = array( ‘description’ => __(‘Use this widget to add one of your custom menu as a link list widget.’) ); parent::__construct( ‘custom_menu_widget-1’, __(‘My name’), $widget_ops ); } function widget($args, $instance) { // Get menu $nav_menu = ! empty( $instance[‘nav_menu’] ) ? … Read more

How to add menu to Dashboard that can be viewed by all users

You have to use the right capability for this. You chose manage_options, which by default only users with an Administrator user role have. So, change it to read or exist, for instance, and every user will be able to see and access the menu. add_dashboard_page( ‘custom menu title’, ‘Test’, ‘read’, ‘custompage’, ‘my_custom_menu_page’, plugins_url( ‘test/images/icon.png’ ), … Read more

Add Page ID class to nav menu items

We can add custom nav menu classes through the nav_menu_css_class filter. Example: The following should add the CSS class wpse-object-id-{object_id} to the <li> tags: // Add filter add_filter( ‘nav_menu_css_class’, ‘wpse_menu_item_id_class’, 10, 2 ); // Your navigational menu wp_nav_menu( $args ); // Remove filter remove_filter( ‘nav_menu_css_class’, ‘wpse_menu_item_id_class’, 10, 2 ); where we define the filter callback … Read more

Directing a page to a default subpage

Using WordPress custom nav menus create a menu and add the “General” page 2 times. The first as the parent and the second as the first child then add the rest of the pages as childs under the first General. Change the title in the first general to movies then on the front end when … Read more

Exclude one item from wp_list_pages( $args );

There’s a filter called wp_list_pages_exclude that you could possibly hook into (put this in your functions.php): function filter_wp_list_pages($exclude){ $exclude[] = 56; return $exclude; } add_filter(“wp_list_pages_excludes”, “filter_wp_list_pages”);