How can I remove a menu item programmatically?
Use the wp_nav_menu_objects filter to adjust the menu items using whatever conditions you like. The filter will receive and return an array of the menu items.
Use the wp_nav_menu_objects filter to adjust the menu items using whatever conditions you like. The filter will receive and return an array of the menu items.
I had to do this too, but didn’t find a quick and easy way. Since jQuery is available in the wp admin, I used that to select all the delete links and trigger the click event on them: jQuery(‘#menu-to-edit’) .find(‘.submitdelete’) .trigger(‘click’);
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
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
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
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
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
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
You can use jQuery to do that. Try this in your header : $(document).ready(function() { $(“#mymenu li:nth-child(3n+3)”).addClass(“last”); }); Note : for this to work you need to have enqueued jQuery.
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”);