[wp-hackers] Strange behavior in plugin with main menu and submenu

Leonid Mamchenkov leonid at mamchenkov.net
Sun Jul 1 12:51:29 GMT 2007

Hi All.

I am writing a self-contained plugin, which adds an item to
administration's main menu. It also adds a few submenus to its main
menu item.  I want all code and formatting and everything to remain in
the same file.  It seems possible judging by this Codex page:
http://codex.wordpress.org/Adding_Administration_Menus , but I can't
make it work.

Here is a sample code to demonstrate the problem (save it in a file in
plugins directory and then active Test plugin):

 * Plugin Name: Test
 * Version: 1.0

function test_menu() {

function page_a() {
    print '<h2>hello from page a</h2>';

function page_b() {
    print '<h2>welcome to page b</h2>';


This gets my menu structure just fine, but the submenu items don't do
anything (don't print out test headings).  If in the test_menu()
function I first do the add_menu_page() and then add_submenu_page(),
then I get everything printed out (both headings from page A and page
B).  I also tried sending __FILE__ parameter to each place which has
to do with files, but it didn't get me anywhere.

Am I doing something wrong?  Is there a bug? Is Codex documentation
accurate?  How can I make this work?

P.S.: I'm currently working around the issue with several files, but
I'd very much rather not. :)


Leonid Mamchenkov

More information about the wp-hackers mailing list