To add custom fields under WordPress general settings without hacking core code, use the below example. Here’s how to add custom field under WordPress general settings page.

add_filter('admin_init', 'register_my_general_settings_fields');
function register_my_general_settings_fields()
{
register_setting('general', 'custom_field', 'esc_attr');
add_settings_field('custom_field', '<label for="custom_field">'.__('Custom Field' , 'custom_field' ).'</label>' , 'general_settings_custom_fields_html', 'general');
}
function general_settings_custom_fields_html()
{
$value = get_option( 'custom_field', '' );
echo '<input type="text" id="custom_field" name="custom_field" value="' . $value . '" />';
}

Please let me know, If you have any queries or feedback.

Leave a Reply

Your email address will not be published. Required fields are marked *