I’m trying to show a custom taxonomy under a admin menu item which is just a page i.e. http://example.com/wp-admin/admin.php?page=bla.
According to the WordPress Dev. page for show_in_menu
under register_taxonomy it says the following:
‘some string’ – If an existing top level page such as ‘tools.php’ or ‘edit.php?post_type=page’, the post type will be placed as a sub menu of that.
Does this mean taxonomies cannot be shown under anything but those?
PHP
<?php
// hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_book_taxonomies', 0 );
// create two taxonomies, genres and writers for the post type "book"
function create_book_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Genres', 'taxonomy general name' ),
'singular_name' => _x( 'Genre', 'taxonomy singular name' ),
'search_items' => __( 'Search Genres' ),
'all_items' => __( 'All Genres' ),
'parent_item' => __( 'Parent Genre' ),
'parent_item_colon' => __( 'Parent Genre:' ),
'edit_item' => __( 'Edit Genre' ),
'update_item' => __( 'Update Genre' ),
'add_new_item' => __( 'Add New Genre' ),
'new_item_name' => __( 'New Genre Name' ),
'menu_name' => __( 'Genre' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_in_menu' => 'bla', // not working | tried admin.php?page=bla as well, also not working
'show_admin_column' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'genre' ),
);
register_taxonomy( 'genre', array( 'book' ), $args );
}
I’ve found a way around this problem, code below:
In your Taxonomy registration:
You then need to add a submenu page:
finally:
Hope I put all that in correctly. Nest any else if’s inside the taxonomy check and add same for other post types.
Let’s say our taxonomy slug will be
vendor
and the parent menu we want to put it under will bemy_menu
.To grant access, the default
manage_categories
capability is used. This needs to match the one provided toregister_taxonomy
function in thecapabilities
array passed in the$args
argument.