I have a custom plugin with an options page that is working great. I have set up multiple tabs that include content on each. I have now added each of these tabs as submenu items successfully, but I'm having trouble adding the current class to them when the user is viewing that tab.

Here is my code:

add_action( 'admin_menu', 'eri_Add_My_Admin_Link' );
function eri_Add_My_Admin_Link() {
    // The 'slug'
    $slug = 'eri-webtools-plugin/includes/admin/eri-admin-page.php';
    // Get notification count
    $warning = eriErrorCount();
    $notif = '';
    if ($warning > 0) {
        $notif = '<span class="awaiting-mod">'.$warning.'</span>';
    // Add a new top level menu link to the ACP
        'ERI Web Tools', // Title of the page
        $warning ? 'ERI Tools '.$notif : 'ERI Web Tools', // Text to show on the menu link
        'manage_options', // Capability requirement to see the link
        $slug, // The 'slug' - file to display when clicking the link
        plugins_url( 'eri-webtools-plugin/includes/admin/star15x15.png' ), // The admin menu icon
    // Add submenu
    global $submenu;
    $tab_path = '/wp-admin/admin.php?page=eri-webtools-plugin%2Fincludes%2Fadmin%2Feri-admin-page.php&tab=';
    // Welcome
    $permalink1 = '/wp-admin/admin.php?page=eri-webtools-plugin%2Fincludes%2Fadmin%2Feri-admin-page.php';
    $submenu[$slug][] = array( 'Welcome', 'manage_options', $permalink1 );
    // Settings
    $permalink2 = $tab_path.'settings';
    $submenu[$slug][] = array( 'Settings', 'manage_options', $permalink2 );
    // Debug
    $permalink3 = $tab_path.'debug';
    $submenu[$slug][] = array( 'Debug', 'manage_options', $permalink3 );
    //call register settings function
    add_action( 'admin_init', 'register_eri_plugin_settings' );

Any suggestions?

The current class shows up on the <li> and the <a>, but I really only need it on the <li>.

Here is what the "Posts" menu/submenu looks like when on the Categories page:

<li class="wp-has-submenu wp-has-current-submenu wp-menu-open menu-top menu-icon-post open-if-no-js" id="menu-posts">
    <a href="edit.php" class="wp-has-submenu wp-has-current-submenu wp-menu-open menu-top menu-icon-post open-if-no-js" aria-haspopup="false">
        <div class="wp-menu-arrow"><div></div></div>
        <div class="wp-menu-image dashicons-before dashicons-admin-post" aria-hidden="true"><br></div>
        <div class="wp-menu-name">Posts</div>
    <ul class="wp-submenu wp-submenu-wrap">
        <li class="wp-submenu-head" aria-hidden="true">Posts</li>
        <li class="wp-first-item"><a href="edit.php" class="wp-first-item">All Posts</a></li>
        <li><a href="post-new.php">Add New</a></li>
        <li class="current"><a href="edit-tags.php?taxonomy=category" class="current" aria-current="page">Categories</a></li>
        <li><a href="edit-tags.php?taxonomy=post_tag">Tags</a></li>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.