I remembered a question I answered in March this year, so you may want to check it out here, but to highlight your “Landing Pages” menu item, you can do it like so:
Note: It will be up to you on how to implement the code in your class, but just let me know if you have any questions regarding the code.
-
Add the custom menu item:
function add_landing_pages_admin_menu() { $slug = 'edit.php?post_type=page&libray_type=landing_page'; add_menu_page( 'Landing Pages', 'Landing Pages', 'manage_options', $slug ); } add_action( 'admin_menu', 'add_landing_pages_admin_menu' );
-
Change the “Pages” and “All Pages” menu items so that they do not get highlighted, but note that we’re not changing the (global)
$parent_file
value here (refer to step #3 for that part).function fix_admin_parent_file_override( $menu ) { global $pagenow, $submenu, $parent_file; // If we're not on the edit.php page, do nothing. if ( ! is_admin() || 'edit.php' !== $pagenow || 'edit.php?post_type=page' !== $parent_file ) { return $menu; } // Same as in the above add_landing_pages_admin_menu(). $slug = 'edit.php?post_type=page&libray_type=landing_page'; // Make sure the $parent_file is not overriden (by WordPress) to the 'Pages' menu. if ( isset( $_GET['libray_type'] ) && 'landing_page' === $_GET['libray_type'] ) { // Add an empty libray_type query to the 'Pages' URL. $menu[20][2] .= '&libray_type="; $submenu[ $menu[20][2] ] = $submenu["edit.php?post_type=page']; // Then set the 'All Pages' URL to the same as the 'Pages' URL. $submenu[ $menu[20][2] ][5][2] = $menu[20][2]; unset( $submenu['edit.php?post_type=page'] ); } return $menu; } add_filter( 'add_menu_classes', 'fix_admin_parent_file_override' );
-
Now change the
$parent_file
which then highlights the custom menu item added via step #1 above.function highlight_landing_pages_admin_menu( $parent_file ) { if ( isset( $_GET['libray_type'] ) && 'landing_page' === $_GET['libray_type'] && 'edit.php?post_type=page' === $parent_file ) { // Return the $slug value as in the above add_landing_pages_admin_menu() return 'edit.php?post_type=page&libray_type=landing_page'; } return $parent_file; } add_filter( 'parent_file', 'highlight_landing_pages_admin_menu' );
BTW, that libray_type
seems like a typo.. did you mean library_type
?