WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Moving Taxonomy UI to another main menu (5 posts)

  1. Tammy Hart
    Member
    Posted 2 years ago #

    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

  2. Tammy Hart
    Member
    Posted 2 years ago #

    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.

  3. sam_benne
    Member
    Posted 2 years ago #

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

  4. Tammy Hart
    Member
    Posted 2 years ago #

    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');
  5. Ryan Hellyer
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic