Last active
February 13, 2024 12:42
-
-
Save rilwis/c8a524a28917ce3489dcd8db1612bf04 to your computer and use it in GitHub Desktop.
Move the admin menu for custom taxonomy in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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