WordPress插件:add_submenu_page添加顶级菜单项

时间:2019-01-20 23:35:21

标签: wordpress

我创建了一个包含两个子菜单项的菜单。但是,在附加了代码的情况下,它将顶级名称“ management”添加为第一子菜单项。如何停止呢?

class Personalize_Login_Plugin {

    public function __construct() {
            add_action( 'admin_menu', array( $this, 'my_admin_menu' ));
    }
    public function my_admin_menu() {
            add_menu_page( 'Project Management', 'Project Management', 'manage_options', 'testing_page', array( $this, 'my_admin_page' ), 'dashicons-star-filled', 6);
            add_submenu_page( 'testing_page', 'Trials', 'Trials', 'manage_options', 'sp-trials', array( $this, 'my_trials_page' ));
            add_submenu_page( 'testing_page', 'Enrolments', 'Enrolments', 'manage_options', 'sp-enrolments', array( $this, 'my_enrolments_page' ));
    }

    public function my_admin_page(){

        ?>
        <h3>Testing options</h3>
        <div>put more stuf here</div>
        <?php
    }
}

1 个答案:

答案 0 :(得分:1)

尝试此代码。

class Personalize_Login_Plugin {

    public function __construct() {
            add_action( 'admin_menu', array( $this, 'my_admin_menu' ));
    }
    public function my_admin_menu() {
            add_menu_page( 'Project Management', 'Project Management', 'manage_options', 'sp-trials', array( $this, 'my_admin_page' ), 'dashicons-star-filled', 6);
            add_submenu_page( 'sp-trials', 'Trials', 'Trials', 'manage_options', 'sp-trials', array( $this, 'my_trials_page' ));
            add_submenu_page( 'sp-trials', 'Enrolments', 'Enrolments', 'manage_options', 'sp-enrolments', array( $this, 'my_enrolments_page' ));
    }

    public function my_admin_page(){

        ?>
        <h3>Testing options</h3>
        <div>put more stuf here</div>
        <?php
    }
}

$Personalize_Login_Plugin = new Personalize_Login_Plugin();