I'm looking for a way to set the default "Automatically add new top-level pages" to be checked when creating a new menu. I haven't been able to find anything on this - any help you could give me? Thanks!
2 Answers
<?php
add_action( 'wp_create_nav_menu', 'PREFIX_nav_menu_auto_add_by_default' );
function PREFIX_nav_menu_auto_add_by_default( $id ) {
$options = (array) get_option( 'nav_menu_options' );
if ( ! isset( $options['auto_add'] ) ) {
$options['auto_add'] = array();
}
$options['auto_add'][] = $id;
update_option( 'nav_menu_options', $options );
}
-
Just want to clarify draebb's answer '$id' is the menu id that we want the top level pages to be added to automatically. So if we want to get the menu $menu_obj = wp_get_nav_menu_object( $menu_name ); and then $menu_id = $menu_obj->term_id; // yes, the menu is a taxonomy. Jun 7, 2016 at 15:42
When you create menu check there's a check box "Automatically add new top-level pages " just check it and save
-
Hi - this is more to have this option checked by default instead of having to check it off each time (for client work). Little miffed on where this is stored/if we can edit that. Thanks!– ZachNov 29, 2011 at 14:15