plugin development - How to add admin.php to WP Admin Menu Link

admin2025-06-02  2

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');

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');
Share Improve this question edited Mar 14, 2019 at 20:14 Omicans asked Mar 14, 2019 at 14:58 OmicansOmicans 1012 bronze badges 4
  • You have to add the menu page (add_menu_page()) before adding the submenu page. – Max Yudin Commented 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 Commented 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 Commented Mar 14, 2019 at 15:58
  • @MaxYudin I added that. – Omicans Commented Mar 14, 2019 at 20:14
Add a comment  | 

1 Answer 1

Reset to default 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;
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748804098a313856.html

最新回复(0)