Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
[WordPress] Highlight an Active Submenu in the Back-End
add_filter( 'parent_file', 'acme_highlight_draft_submenu' );
* Highlights the 'Draft' submenu item using WordPress native styles.
* @param string $parent_file The filename of the parent menu.
* @return string $parent_file The filename of the parent menu.
function acme_highlight_draft_submenu( $parent_file ) {
global $submenu_file;
// Only update the submenu file value if we're on the Draft page.
if ( 'draft' === get_query_var( 'post_status' ) ) {
$args = array( 'post_status' => 'draft', );
// Use the full URL so get the admin URL and concatenate it with the parent file.
$admin_url = trailingslashit( get_admin_url() );
$url = sprintf( '%s%s', $admin_url, $parent_file );
$submenu_file = add_query_arg( $args, $url );
return $parent_file;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment