Skip to content

Instantly share code, notes, and snippets.

@yiedpozi
Created September 2, 2020 16:54
Show Gist options
  • Save yiedpozi/a13ab6ffa5d9e387da49268a5146458a to your computer and use it in GitHub Desktop.
Save yiedpozi/a13ab6ffa5d9e387da49268a5146458a to your computer and use it in GitHub Desktop.
Highlight custom post type menu under WooCommerce
// Highlight custom post type menu registered under WooCommerce (sub menu)
add_action( 'admin_head', 'menu_highlight' );
function menu_highlight() {
global $parent_file, $submenu_file, $post_type;
if ( $post_type == 'custom_post_type' ) {
// We change $submenu_file to current $parent_file,
// so the $submenu_file for post type add and edit screen is same.
$submenu_file = $parent_file;
// Then, we change $parent_file to woocommerce,
// so when we navigate to post type add or edit screen,
// WooCommerce admin menu will be opened.
$parent_file = 'woocommerce';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment