Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Manually highlight Wordpress admin menu item

Tags:

wordpress

Under Pages menu in Wordpress Admin page, I got this layout:

Pages

  • Edit (url: edit-pages.php)
  • Add New (url: page-new.php)
  • Special Pages (url: edit-pages.php?special-pages=true)

as you can see, I've added a new submenu item called Special Pages which is pretty much a link to to Edit page with custom filter. Because Wordpress use file name to identify and highlight the submenu item, so whenever I click on Special Pages, the Edit submenu item is selected. Is there anyway to force Wordpress to select Special Pages menu item instead?

Cheers

like image 956
Ken Vu Avatar asked Feb 22 '10 03:02

Ken Vu


People also ask

Where is the Admin menu in WordPress?

You can access the the menu editor by going to Settings -> Menu Editor. The plugin will automatically load your current menu configuration the first time you run it. If you have WordPress set up in Multisite (“Network”) mode, you can also install Admin Menu Editor as a global plugin.

How do I use the menu editor in WordPress?

Step 1: Navigate to Appearance -> Menu. Step 2: The Menu contains a list of pages that are currently in your menu. To edit a menu item, click the drop-down arrow next to the appropriate menu item. Step 4: You can the order of your menu by dragging the titles to re-order the Menu.


1 Answers

better solution:

add_filter('parent_file', 'my_plugin_select_submenu');
function my_plugin_select_submenu($file) {
        global $plugin_page;
        if ('__my-current-submenu-slug__' == $plugin_page) {
            $plugin_page = '__my-submenu-slug-to-select__';
        }
        return $file;
}
like image 182
tutankhamun Avatar answered Nov 15 '22 23:11

tutankhamun