Theme menu in Admin Panel

You need to register custom menus in your theme – https://codex.wordpress.org/Function_Reference/register_nav_menu You first need to register your menu in functions.php like so: add_action( ‘after_setup_theme’, ‘register_my_menu’ ); function register_my_menu() { register_nav_menu( ‘primary’, __( ‘Primary Menu’, ‘theme-slug’ ) ); } Then, where you want your menu to appear – usually header.php – you call the function: wp_nav_menu()

How to add pages to custom menus on the fly [duplicate]

I guess it doesn’t need anymore explanation: $mymenu = wp_get_nav_menu_object(‘Main Navigation Menu’); $menuID = (int) $mymenu->term_id; $myPage = get_page_by_title(‘About Us’); $itemData = array( ‘menu-item-object-id’ => $myPage->ID, ‘menu-item-parent-id’ => 0, ‘menu-item-position’ => 2, ‘menu-item-object’ => ‘page’, ‘menu-item-type’ => ‘post_type’, ‘menu-item-status’ => ‘publish’ ); wp_update_nav_menu_item($menuID, 0, $itemData);

How to remove div container in custom menu?

Set the container to be empty. 🙂 wp_nav_menu( array( ‘menu_class’ => ‘tlm’, ‘theme_location’ => ‘primary-menu’, ‘container’ => ” ) ); Please refer to the function reference to review all the arguments that you can pass to wp_nav_menu().

Remove the whole menu in the admin

add_action(‘admin_head’, ‘t5_hide_menu’); function t5_hide_menu() { $GLOBALS[‘menu’] = array(); ?> <style>#adminmenuback,#adminmenuwrap{display:none !important} #wpcontent, #footer{margin-left:0 !important}</style> <?php } Now I want to know: why? 🙂

wp_nav_menu and fallback

Simply set it to a predefined core-function that returns null or false: ‘fallback_cb’ => ‘__return_zero’ // or ‘fallback_cb’ => ‘__return_false’

Sort wp_nav_menu() by menu order

The nav_menu_items are already sorted by menu_order. When you go into the Appearance -> Menus and arrange the order menu the menu_order of each menu item gets updated. To change the orderby parameter in the query that displays the menu you can use pre_get_posts to alter it. Example: add_action( ‘pre_get_posts’, ‘wpse_sort_nav’ ); function wpse_sort_nav( $query … Read more

WP Nav menu append to url

I found the solution modifying the behaviour of wp_nav_menu with the wp_get_nav_menu_items-filter. Here’s a somewhat complete example: class ModifyLinkFilter { protected $_prio = 10; protected $_args; public function __construct($addargs = array(), $prio = 10) { $this->_args = $addargs; $this->_prio = $prio; if(!empty($addargs)) { $this->register(); } } public function register() { add_filter(‘wp_get_nav_menu_items’, array($this, ‘on_nav_items’), $this->_prio, 3); … Read more