0

I am trying to add a menu link in wordpress admin navigation bar. I am expecting a link like

/wp-admin/admin.php?page=function_name

The code I am using is

add_submenu_page( 'nxssnap',__( 'Calendar View', 'social-networks-auto-poster-facebook-twitter-g' ), __( 'Calendar View', 'social-networks-auto-poster-facebook-twitter-g' ), 'manage_options', 'nxs-function_name', array( $this, 'showPage_about' ) ,0 );

The link that I get from the above code is

/wp-admin/function_name

What change do I need to make so that appends this admin.php?page= at the start of URL

This is the main menu item for which i am trying to add submenu.

$this->page = add_menu_page( 'Social Networks Auto Poster', 'SNAP|AutoPoster','haveown_snap_accss','nxssnap',array( $this, 'showPage_accounts' ), NXS_PLURL.'img/snap-icon.png');
4
  • You have to add the menu page (add_menu_page()) before adding the submenu page.
    – Max Yudin
    Mar 14, 2019 at 15:37
  • I am trying to add this as a sub-menu item under an already added main menu page
    – Omicans
    Mar 14, 2019 at 15:45
  • 1
    If so, please, edit the question and add the missing code responsible for the parent menu page.
    – Max Yudin
    Mar 14, 2019 at 15:58
  • @MaxYudin I added that.
    – Omicans
    Mar 14, 2019 at 20:14

1 Answer 1

0

Looks you are adding pages the wrong way.

Here how it should look inside the class:

class My_Add_Menu_Pages {

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

    public function my_custom_admin_pages() {
        add_menu_page(
            'Social Networks Auto Poster',
            'SNAP|AutoPoster',
            'haveown_snap_accss',
            'nxssnap',
            array(
                $this,
                'showPage_accounts'
            )
        );

        add_submenu_page(
            'nxssnap',
            __( 'Calendar View', 'social-networks-auto-poster-facebook-twitter-g' ),
            __( 'Calendar View', 'social-networks-auto-poster-facebook-twitter-g' ),
            'manage_options',
            'nxs-function_name',
            array(
                $this,
                'showPage_about'
            )
        );
    }

    public function showPage_accounts() {
        echo '<h1>Parent Page</h1>';
    }

    public function showPage_about() {
        echo '<h1>Child Page</h1>';
    }
}

new My_Add_Menu_Pages;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.