Add custom field under settings general tab in WordPress

WordPress add custom field under settings general tab

As we all know WordPress is very popular and easy to create an application and website in WordPress. Once we need to add custom field example footer social links or content, simply add wp hooks example below (this code snippet will create social links textbox and textarea). As per our Australian client requirement, we add custom fields in WordPress opensource. For WP page speed or security we recommend adding customized code, not plugins.

//general settings could add in function.php or your plugin file
add_action('admin_init', 'my_general_section');

function my_general_section() {
add_settings_section(
'my_settings_section', // Section ID
'Footer Setting', // Section Title
'my_section_options_callback', // Callback function
'general' // Show up on the General Settings Page
);

add_settings_field( 'fcontent', 'Content', 'my_textarea_callback', 'general', 'my_settings_section', array('fcontent' ) );

add_settings_field( 'fbook', 'Facebook', 'my_textbox_callback', 'general', 'my_settings_section', array('fbook' ) );
add_settings_field( 'instagram', 'Instagram', 'my_textbox_callback', 'general', 'my_settings_section', array('instagram' ) );
add_settings_field( 'tlink', 'Twitter', 'my_textbox_callback', 'general', 'my_settings_section', array('tlink' ) );
add_settings_field( 'linkedin', 'LinkedIn', 'my_textbox_callback', 'general', 'my_settings_section', array('linkedin' ) );
add_settings_field( 'youtube', 'Youtube', 'my_textbox_callback', 'general', 'my_settings_section', array('youtube' ) );

register_setting('general','fcontent', 'esc_attr');
register_setting('general','fbook', 'esc_attr');
register_setting('general','instagram', 'esc_attr');
register_setting('general','tlink', 'esc_attr');
register_setting('general','linkedin', 'esc_attr');
register_setting('general','youtube', 'esc_attr');
}

function my_section_options_callback() { // Section Callback
echo '<p>Footer Setting</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 . '" />';
}

function my_textarea_callback($args) { // Textarea Callback
$option = get_option($args[0]);
echo '<textarea id="'. $args[0] .'" name="'. $args[0] .'">' . $option . '</textarea>';
}

//Get custom field value, anywhere in frontend code.

get_option('fbook');