1

I've created some custom fields on the General Settings page after studying up on this post: Add multiple custom fields to the general settings page.

I'd really like to move them to their own location - preferably a new menu item, or at least under the Settings menu item. I seen tutorials on how to add a new options page under Settings, but haven't gotten these options to show up there:

add_action('admin_init', 'my_general_section'); 

function my_general_section() {  

add_settings_section(  
'my_settings_section', // Section ID 
'Site Info', // Section Title
'my_section_options_callback', // Callback
'general' // What Page?  This makes the section show up on the General Settings Page
);

add_settings_field( // Phone Number
'phonenumber', // Option ID
'Phone Number', // Label
'my_textbox_callback', // !important - This is where the args go!
'general', // Page it will be displayed (General Settings)
'my_settings_section', // Name of our section
array( // The $args
'phonenumber' // Should match Option ID
 )  
); 
add_settings_field( // State
    'state', // Option ID
    'State', // Label
    'my_textbox_callback', // !important - This is where the args go!
    'general', // Page it will be displayed
    'my_settings_section', // Name of our section (General Settings)
    array( // The $args
        'state' // Should match Option ID
    )  
); 
register_setting('general','phonenumber', 'esc_attr');
register_setting('general','state', 'esc_attr');
}

function my_section_options_callback() { // Section Callback
echo '<p>Additional Settings</p>';  
}

function my_textbox_callback($args) {  // Textbox Callback
$option = get_option($args[0]);
echo '<input type="text" id="'. $args[0] .'" name="'. $args[0] .'" value="' . $option . '" />';
}

What am I missing or what do I need to add? I've tried adding the following, but the fields didn't show up:

add_action('admin_menu', 'theme_options_page'); 

function theme_options_page() { add_options_page('Theme Settings', 'Theme Settings', 'administrator', __FILE__, 'build_options_page');

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.