Last active
February 8, 2018 20:58
-
-
Save davidsword/b4bde696c96486a41b3abab6b64b36d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('admin_menu', function () { | |
$parent_slug = 'edit.php?post_type=page'; // "Pages" | |
$page_title = 'My Plugin Submenu Page'; | |
$menu_title = 'My Plugin Submenu Page'; | |
$capability = 'edit_pages'; | |
$menu_slug = 'myplugin-submenu-page'; | |
$page = 'myplugin_submenu_page'; | |
add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $page); | |
}); | |
function myplugin_submenu_page(){ | |
echo "<h1>Sub menu page content goes here.</h1>"; | |
} | |
// global $menu, $submenu; | |
// echo "<pre>MENU: \n".print_r($menu,true)."</pre>"; | |
// echo "<pre>SUB-MENU: \n".print_r($submenu,true)."</pre>"; | |
// die; | |
// TO MODIFY INSTEAD: | |
add_action( 'admin_menu', function () { | |
global $menu, $submenu; | |
foreach ($menu as $menuKey => $menuItem) | |
if ($menuItem[0] == 'Products') | |
$menu[$menuKey][2] = 'https://google.com/'; // wtv link you want | |
// UPDATE: | |
// remove the sub menu as well (note the GLOBAL var define above) | |
$submenu['edit.php?post_type=product'] = ''; | |
unset($submenu['edit.php?post_type=product']); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment