• Resolved Tammy Hart

    (@tammyhart)


    I have created a few custom taxonomies for the post post_type for my recipe plugin. I set show_ui to false to remove it as a submenu item under Posts. Then I added it as a submenu page for my Recipe plugin options page with this code:

    add_submenu_page( 'recipe_box_options', 'Ingredients', 'Ingredients', 'edit_others_posts', 'edit-tags.php?taxonomy=ingredient');

    This works great and links correctly. My only issue is that it adds the wp-has-current-submenu class to the Posts top level menu, instead of the Recipe Box Options top level menu.

    Here’s a screenshot for clarification: http://screencast.com/t/XBmpgouUeOW

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter Tammy Hart

    (@tammyhart)

    Perhaps not the most elegant solution, but the highlighting is half working.

    function recipe_tax_menu_correction($parent_file) {
    	global $current_screen;
    	$taxonomy = $current_screen->taxonomy;
    	if ($taxonomy == 'ingredient' || $taxonomy == 'cuisine' || $taxonomy == 'course' || $taxonomy == 'skill_level')
    		$parent_file = 'recipe_box_options';
    	return $parent_file;
    }
    add_action('parent_file', 'recipe_tax_menu_correction');
    

    It’s selecting the Recipe Box top level menu, but it’s not highlighting the actual taxonomy link. Good enough for me.

    I am to having this problem. Lets see if I can work this out.

    Thread Starter Tammy Hart

    (@tammyhart)

    I actually did figure this out, but failed to post it. Glad you reminded me.

    Basically, you just manually set the parent file, which is how the highlighting is determined.

    add_action( 'admin_menu', 'recipress_add_page' );
    function recipress_add_page() {
    	add_menu_page( 'Recipe Box Options', 'Recipe Box', 'edit_others_posts', 'recipress_options', 'recipress_do_page' );
    	add_submenu_page( 'recipress_options', 'Recipe Box Options', 'Recipe Box Options', 'edit_others_posts', 'recipress_options', 'recipress_do_page');
    	add_submenu_page( 'recipress_options', 'Ingredients', 'Ingredients', 'edit_others_posts', 'edit-tags.php?taxonomy=ingredient');
    	add_submenu_page( 'recipress_options', 'Cuisines', 'Cuisines', 'edit_others_posts', 'edit-tags.php?taxonomy=cuisine');
    	add_submenu_page( 'recipress_options', 'Courses', 'Courses', 'edit_others_posts', 'edit-tags.php?taxonomy=course');
    	add_submenu_page( 'recipress_options', 'Skill Levels', 'Skill Levels', 'edit_others_posts', 'edit-tags.php?taxonomy=skill_level');
    }
    
    // highlight the proper top level menu
    function recipe_tax_menu_correction($parent_file) {
    	global $current_screen;
    	$taxonomy = $current_screen->taxonomy;
    	if ($taxonomy == 'ingredient' || $taxonomy == 'cuisine' || $taxonomy == 'course' || $taxonomy == 'skill_level')
    		$parent_file = 'recipress_options';
    	return $parent_file;
    }
    add_action('parent_file', 'recipe_tax_menu_correction');

    Thanks Tammy! I was struggling to figure this out, but your code works great 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Moving Taxonomy UI to another main menu’ is closed to new replies.