Dynamically Create Theme Location for Menu
-
I’m trying to dynamically add a theme location for a custom menu and I’d like to do that each time I create a new post under a custom post type. The idea is that each custom post type could have a custom menu. There will only be a few posts under that custom post type.
Here is what I have added to the functions file, but it doesn’t seem to work. Any suggestions or issues that can be easily seen?
function add_registered_menu($post_id) { $slug = 'players'; // If this isn't a 'players' post, don't update it. if ( $slug != $_POST['post_type'] ) { return; } if ( wp_is_post_revision( $post_id ) ) return; $menu_loc_name = get_the_title($post_id); $menu_loc = basename(get_permalink($post_id)); register_nav_menu($menu_loc, $menu_loc_name); } add_action ('save_post', 'add_registered_menu');
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Dynamically Create Theme Location for Menu’ is closed to new replies.