Title: Dynamically Create Theme Location for Menu
Last modified: August 21, 2016

---

# Dynamically Create Theme Location for Menu

 *  [gnat2000](https://wordpress.org/support/users/gnat2000/)
 * (@gnat2000)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/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)

 *  Thread Starter [gnat2000](https://wordpress.org/support/users/gnat2000/)
 * (@gnat2000)
 * [12 years, 6 months ago](https://wordpress.org/support/topic/dynamically-create-theme-location-for-menu/#post-4319662)
 * 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.

## Tags

 * [register_nav_menu](https://wordpress.org/support/topic-tag/register_nav_menu/)
 * [save_post](https://wordpress.org/support/topic-tag/save_post/)

 * 1 reply
 * 1 participant
 * Last reply from: [gnat2000](https://wordpress.org/support/users/gnat2000/)
 * Last activity: [12 years, 6 months ago](https://wordpress.org/support/topic/dynamically-create-theme-location-for-menu/#post-4319662)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
