0

I'm doing a plugin. In this plugin I have to add a submenu for Settings.

Code :

 public function __construct(){
     add_action( 'admin_menu', array( $this, 'add_setting_page' ) );
 }

 public function add_setting_page(){ 
     add_options_page(
            $this->page_title,
            PLUGIN_SHORT_TITLE,
            'manage_options',
            $this->menu_slug,
            array( $this, 'html_page_template' )
    );
}

With the function add_options_page in the official documentation, it's written :

This function takes a capability which will be used to determine whether or not a page is included in the menu.

I manage to go to the right page using a custom link :

<a href="/wp-admin/options-general.php?page=my-slug">Custom link</a>

But otherwise, the submenu does not appear in Settings menu. How do I need to add to show it in the Settings menu all the time ?

  • do you add the page in the action "admin_menu" ? – mmm Oct 26 '17 at 13:29
  • Yes I did. If Idid not, I could not see my page with a custom link. I modified my answer to be clearer. – J.BizMai Oct 26 '17 at 13:32
  • and when do you instanciate the class ? in the plugin main file ? – mmm Oct 26 '17 at 13:34
  • I'm using classes with namespace, I cannot put all my code here. The function is called. It is not the problem. – J.BizMai Oct 26 '17 at 13:38

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.