Skip to content

Instantly share code, notes, and snippets.

@contactjavas
Last active October 8, 2019 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save contactjavas/73be134020f738bd3262884bbe69303a to your computer and use it in GitHub Desktop.
Save contactjavas/73be134020f738bd3262884bbe69303a to your computer and use it in GitHub Desktop.
WordPress: Change admin submenu's url
<?php
$menu_key = 'edit.php?post_type=contact_form';
// Submenu's slug to be replaced.
$search = 'contact_submission';
// Url to replace the slug.
$replace = 'edit.php?post_type=contact_submission';
add_action( 'admin_menu', 'change_admin_submenu_url' );
/**
* Change the submenu's url.
*/
function change_admin_submenu_url() {
global $submenu;
if ( ! isset( $submenu[ $menu_key ] ) ) {
return;
}
// When exist, $submenu[$menu_key] is always array.
foreach ( $submenu[ $menu_key ] as $index => $values ) {
$break = false;
if ( $values && is_array( $values ) ) {
foreach ( $values as $key => $value ) {
if ( $value === $search ) {
$submenu[ $menu_key ][ $index ][ $key ] = $replace;
$break = true;
break;
}
}
}
if ( $break ) {
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment