I have a plugin page created with add_submenu_page
, I want to add a new section there but nothing happens:
add_submenu_page('parent', 'Foo', 'Foo', 'manage_options', 'foo-settings', 'anothercallback');
add_settings_section('foo-settings-section', 'Settings', 'acallback', 'foo-settings');
What’s the right call to use it in a custom page? Do you have a complete example?
The
add_settings_section()
function simply registers a form section with a certain slug with WordPress. In order to get the section and all the fields you’ve added to it to display on a certain menu page, you need to include thedo_settings_sections($sections-slug)
method in the menu’s callback. This is, of course, assuming you are using the Settings API, whichadd_settings_section
is part of.Example:
I did my best to keep all the parameter names unique, so you should be able to pick them apart and trace where they go. The Settings API gets very specific about what needs to go where, so make sure you have that all right. Also, keep in mind that I omitted all the callback functions from this example, but in reality they are necessary.
This is your problem, in your
add_submenu_page()
callback:For
settings_fields()
:$optiongroup
parameter you passed toregister_setting()
.For
do_settings_sections()
:do_settings_sections()
, notdo_settings_section()
(note plural)$pageid
parameter you passed toadd_submenu_page()
.EDIT
Er, nevermind. I was responding to someone else’s answer, which I misread as the actual callback function markup. The answers here may or may not apply; we still need to see the full code, including callbacks.