add_options_page slug not working with add_settings_section
-
I’m trying to create an options page for my plugin, however when I use add_options_page, it creates the page, but my add_settings_section/field /register_setting don’t latch onto it. I’ve gotten all of these examples from the wordpress/codex website, so I presume it’s correct.
The submenu item
settings > Roshan's functions
is appearing fine, but it only contains the title and text from below. Not the form or text input.They do however work perfectly fine if I set them to go onto page general as in the example below.
Wherever it saysgeneral
below, if replaced withroshans_settings
causes the settings to stop appearing (on any page).add_action( 'admin_menu', 'roshans_custom_admin_settings' ); function roshans_custom_admin_settings() { add_options_page( 'Roshan\'s Functions', 'Roshan\'s Functions', 'manage_options', 'roshans_settings', 'roshans_function_options' ); } function roshans_function_options() { ?> <div class="wrap"> <h2>My Plugin Options</h2> your form goes here </div> <?php } /* * Add all your sections, fields and settings during admin_init */ function roshans_settings_api_init() { // Add the section to roshans_settings settings so we can add our fields to it add_settings_section( 'roshans_setting_section', 'Menu Settings', 'roshans_setting_section_callback_function', 'general' ); // Add the field with the names and function to use for our new settings, put it in our new section add_settings_field( 'roshans_menu_loc', 'Menu Location', 'roshans_setting_callback_function', 'general', 'roshans_setting_section' ); // Register our setting in the "roshans_settings" settings section register_setting( 'general', 'roshans_menu_loc' ); } add_action( 'admin_init', 'roshans_settings_api_init' ); /* * Settings section callback function */ function roshans_setting_section_callback_function() { echo '<p>Settings for Roshan\'s functions</p>'; } /* * Callback function for our example setting */ function roshans_setting_callback_function() { $setting = esc_attr( get_option( 'roshans_menu_loc' ) ); echo "<input type='text' name='roshans_menu_loc' value='$setting' />"; }
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘add_options_page slug not working with add_settings_section’ is closed to new replies.