• gnat2000

    (@gnat2000)


    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)
  • Thread Starter gnat2000

    (@gnat2000)

    I’m guessing that this will never work because register_nav_menu() has to remain there and tying into save_post will only create it as that is happening and then it’s gone.

    Is there a way to take $menu_loc_name and $menu_loc and save them as a static function once they have been created?

Viewing 1 replies (of 1 total)
  • The topic ‘Dynamically Create Theme Location for Menu’ is closed to new replies.