Skip to content

Instantly share code, notes, and snippets.

@rilwis
Last active February 13, 2024 12:42
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rilwis/c8a524a28917ce3489dcd8db1612bf04 to your computer and use it in GitHub Desktop.
Save rilwis/c8a524a28917ce3489dcd8db1612bf04 to your computer and use it in GitHub Desktop.
Move the admin menu for custom taxonomy in WordPress
<?php
add_action( 'admin_menu', 'prefix_move_taxonomy_menu' );
function prefix_move_taxonomy_menu() {
add_submenu_page( 'edit.php?post_type=quiz', esc_html__( 'Sections', 'mb-quiz' ), esc_html__( 'Sections', 'mb-quiz' ), 'manage_categories', 'edit-tags.php?taxonomy=question_section' );
}
<?php
add_action( 'parent_file', 'prefix_highlight_taxonomy_parent_menu' );
function prefix_highlight_taxonomy_parent_menu( $parent_file ) {
if ( get_current_screen()->taxonomy == 'question_section' ) {
$parent_file = 'edit.php?post_type=quiz';
}
return $parent_file;
}
<?php
add_action( 'init', 'prefix_register_question_post_type', 0 );
function prefix_register_question_post_type() {
$labels = array(
'name' => esc_html_x( 'Questions', 'Post Type General Name', 'mb-quiz' ),
'singular_name' => esc_html_x( 'Question', 'Post Type Singular Name', 'mb-quiz' ),
'menu_name' => esc_html__( 'Questions', 'mb-quiz' ),
'name_admin_bar' => esc_html__( 'Question', 'mb-quiz' ),
'archives' => esc_html__( 'Question Archives', 'mb-quiz' ),
'attributes' => esc_html__( 'Question Attributes', 'mb-quiz' ),
'parent_item_colon' => esc_html__( 'Parent Question:', 'mb-quiz' ),
'all_items' => esc_html__( 'Questions', 'mb-quiz' ),
'add_new_item' => esc_html__( 'Add New Question', 'mb-quiz' ),
'add_new' => esc_html__( 'Add New', 'mb-quiz' ),
'new_item' => esc_html__( 'New Question', 'mb-quiz' ),
'edit_item' => esc_html__( 'Edit Question', 'mb-quiz' ),
'update_item' => esc_html__( 'Update Question', 'mb-quiz' ),
'view_item' => esc_html__( 'View Question', 'mb-quiz' ),
'view_items' => esc_html__( 'View Questions', 'mb-quiz' ),
'search_items' => esc_html__( 'Search Question', 'mb-quiz' ),
'not_found' => esc_html__( 'Not found', 'mb-quiz' ),
'not_found_in_trash' => esc_html__( 'Not found in Trash', 'mb-quiz' ),
'featured_image' => esc_html__( 'Featured Image', 'mb-quiz' ),
'set_featured_image' => esc_html__( 'Set featured image', 'mb-quiz' ),
'remove_featured_image' => esc_html__( 'Remove featured image', 'mb-quiz' ),
'use_featured_image' => esc_html__( 'Use as featured image', 'mb-quiz' ),
'insert_into_item' => esc_html__( 'Insert into question', 'mb-quiz' ),
'uploaded_to_this_item' => esc_html__( 'Uploaded to this question', 'mb-quiz' ),
'items_list' => esc_html__( 'Questions list', 'mb-quiz' ),
'items_list_navigation' => esc_html__( 'Questions list navigation', 'mb-quiz' ),
'filter_items_list' => esc_html__( 'Filter questions list', 'mb-quiz' ),
);
$args = array(
'label' => esc_html__( 'Question', 'mb-quiz' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => 'edit.php?post_type=quiz',
'show_in_nav_menus' => false,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => true,
'publicly_queryable' => false,
'rewrite' => false,
);
register_post_type( 'question', $args );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment