Last active
December 3, 2022 07:32
-
-
Save johnregan3/6133389 to your computer and use it in GitHub Desktop.
Add Custom Post Type to WordPress Plugin Submenu (Hack)
Thanks for that snippet but to handle custom urls you don't have to use javascript redirection. You can go with something like that:
add_menu_page( __( 'Cposts', $this->plugin_name ), __( 'Cposts', $this->plugin_name ), 'manage_options', '/edit.php?post_type=cpost_post_type', '', 'dashicons-format-gallery', 6 );
add_submenu_page( '/edit.php?post_type=cpost_post_type', __( 'All Cposts', $this->plugin_name ), __( 'All Cposts', $this->plugin_name ), 'manage_options', '/edit.php?post_type=cpost_post_type', '');
add_submenu_page( '/edit.php?post_type=cpost_post_type', __( 'Add New Cpost', $this->plugin_name ), __( 'Add New Cpost', $this->plugin_name ), 'manage_options', '/post-new.php?post_type=cpost_post_type', '');
so you can declare fixed url as menu slug and pass null for function param. Current menu is handled natively in that case.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for the hack. In WP 4.0 which I'm using, I can simply set
'show_in_menu'
in custom post type args to$menu_slug
that I set inadd_menu_page()
that I want to set the CPT as sub menu of and set the priority of a top-level menu function to 9 or lower.